ICU 69.1  69.1
simpletz.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  ********************************************************************************
5  * Copyright (C) 1997-2013, International Business Machines *
6  * Corporation and others. All Rights Reserved. *
7  ********************************************************************************
8  *
9  * File SIMPLETZ.H
10  *
11  * Modification History:
12  *
13  * Date Name Description
14  * 04/21/97 aliu Overhauled header.
15  * 08/10/98 stephen JDK 1.2 sync
16  * Added setStartRule() / setEndRule() overloads
17  * Added hasSameRules()
18  * 09/02/98 stephen Added getOffset(monthLen)
19  * Changed getOffset() to take UErrorCode
20  * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
21  * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
22  * methods that take TimeMode. Added to docs.
23  ********************************************************************************
24  */
25 
26 #ifndef SIMPLETZ_H
27 #define SIMPLETZ_H
28 
29 #include "unicode/utypes.h"
30 
31 #if U_SHOW_CPLUSPLUS_API
32 
38 #if !UCONFIG_NO_FORMATTING
39 
40 #include "unicode/basictz.h"
41 
42 U_NAMESPACE_BEGIN
43 
44 // forward declaration
45 class InitialTimeZoneRule;
46 class TimeZoneTransition;
47 class AnnualTimeZoneRule;
48 
66 public:
67 
79  enum TimeMode {
80  WALL_TIME = 0,
81  STANDARD_TIME,
82  UTC_TIME
83  };
84 
90  SimpleTimeZone(const SimpleTimeZone& source);
91 
98 
103  virtual ~SimpleTimeZone();
104 
114  virtual UBool operator==(const TimeZone& that) const;
115 
127  SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
128 
164  SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
165  int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
166  int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
167  int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
168  int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
169  UErrorCode& status);
207  SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
208  int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
209  int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
210  int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
211  int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
212  int32_t savingsDST, UErrorCode& status);
213 
255  SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
256  int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
257  int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
258  TimeMode savingsStartTimeMode,
259  int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
260  int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
261  int32_t savingsDST, UErrorCode& status);
262 
271  void setStartYear(int32_t year);
272 
315  void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
316  int32_t time, UErrorCode& status);
361  void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
362  int32_t time, TimeMode mode, UErrorCode& status);
363 
375  void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
376  UErrorCode& status);
390  void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
391  TimeMode mode, UErrorCode& status);
392 
409  void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
410  int32_t time, UBool after, UErrorCode& status);
429  void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
430  int32_t time, TimeMode mode, UBool after, UErrorCode& status);
431 
454  void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
455  int32_t time, UErrorCode& status);
456 
481  void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
482  int32_t time, TimeMode mode, UErrorCode& status);
483 
495  void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
496 
510  void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
511  TimeMode mode, UErrorCode& status);
512 
529  void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
530  int32_t time, UBool after, UErrorCode& status);
531 
550  void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
551  int32_t time, TimeMode mode, UBool after, UErrorCode& status);
552 
573  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
574  uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
575 
591  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
592  uint8_t dayOfWeek, int32_t milliseconds,
593  int32_t monthLength, UErrorCode& status) const;
610  virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
611  uint8_t dayOfWeek, int32_t milliseconds,
612  int32_t monthLength, int32_t prevMonthLength,
613  UErrorCode& status) const;
614 
620  virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
621  int32_t& dstOffset, UErrorCode& ec) const;
622 
623 #ifndef U_FORCE_HIDE_DRAFT_API
624 
628  virtual void getOffsetFromLocal(
629  UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
630  UTimeZoneLocalOption duplicatedTimeOpt,
631  int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
632 #endif /* U_FORCE_HIDE_DRAFT_API */
633 
641  virtual int32_t getRawOffset(void) const;
642 
650  virtual void setRawOffset(int32_t offsetMillis);
651 
661  void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
662 
671  virtual int32_t getDSTSavings(void) const;
672 
679  virtual UBool useDaylightTime(void) const;
680 
681 #ifndef U_FORCE_HIDE_DEPRECATED_API
682 
696  virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
697 #endif // U_FORCE_HIDE_DEPRECATED_API
698 
705  UBool hasSameRules(const TimeZone& other) const;
706 
714  virtual SimpleTimeZone* clone() const;
715 
724  virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
725 
734  virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
735 
744  virtual int32_t countTransitionRules(UErrorCode& status) const;
745 
762  virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
763  const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
764 
765 
766 public:
767 
778  virtual UClassID getDynamicClassID(void) const;
779 
791  static UClassID U_EXPORT2 getStaticClassID(void);
792 
793 private:
797  enum EMode
798  {
799  DOM_MODE = 1,
800  DOW_IN_MONTH_MODE,
801  DOW_GE_DOM_MODE,
802  DOW_LE_DOM_MODE
803  };
804 
805  SimpleTimeZone(); // default constructor not implemented
806 
826  void construct(int32_t rawOffsetGMT,
827  int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
828  int32_t startTime, TimeMode startTimeMode,
829  int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
830  int32_t endTime, TimeMode endTimeMode,
831  int32_t dstSavings, UErrorCode& status);
832 
842  static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
843  int8_t dayOfMonth,
844  int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
845  EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
846  int8_t ruleDay, int32_t ruleMillis);
847 
863  void decodeRules(UErrorCode& status);
864  void decodeStartRule(UErrorCode& status);
865  void decodeEndRule(UErrorCode& status);
866 
867  int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts
868  int32_t startTime;
869  TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
870  int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
871  int32_t endTime;
872  int32_t startYear; // the year these DST rules took effect
873  int32_t rawOffset; // the TimeZone's raw GMT offset
874  UBool useDaylight; // flag indicating whether this TimeZone uses DST
875  static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
876  EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
877 
882  int32_t dstSavings;
883 
884  /* Private for BasicTimeZone implementation */
885  void checkTransitionRules(UErrorCode& status) const;
886  void initTransitionRules(UErrorCode& status);
887  void clearTransitionRules(void);
888  void deleteTransitionRules(void);
889  UBool transitionRulesInitialized;
890  InitialTimeZoneRule* initialRule;
891  TimeZoneTransition* firstTransition;
892  AnnualTimeZoneRule* stdRule;
893  AnnualTimeZoneRule* dstRule;
894 };
895 
896 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
897  int32_t dayOfWeek,
898  int32_t time, UErrorCode& status) {
899  setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
900 }
901 
902 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
903  int32_t time,
904  UErrorCode& status) {
905  setStartRule(month, dayOfMonth, time, WALL_TIME, status);
906 }
907 
908 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
909  int32_t dayOfWeek,
910  int32_t time, UBool after, UErrorCode& status) {
911  setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
912 }
913 
914 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
915  int32_t dayOfWeek,
916  int32_t time, UErrorCode& status) {
917  setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
918 }
919 
920 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
921  int32_t time, UErrorCode& status) {
922  setEndRule(month, dayOfMonth, time, WALL_TIME, status);
923 }
924 
925 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
926  int32_t time, UBool after, UErrorCode& status) {
927  setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
928 }
929 
930 inline void
931 SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
932  int32_t& dstOffsetRef, UErrorCode& ec) const {
933  TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
934 }
935 
936 U_NAMESPACE_END
937 
938 #endif /* #if !UCONFIG_NO_FORMATTING */
939 
940 #endif /* U_SHOW_CPLUSPLUS_API */
941 
942 #endif // _SIMPLETZ
virtual UBool useDaylightTime(void) const =0
Queries if this time zone uses daylight savings time.
virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition &result) const =0
Gets the most recent time zone transition before the base time.
virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, uint8_t dayOfWeek, int32_t millis, UErrorCode &status) const =0
Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add to GMT to get loc...
UTimeZoneLocalOption
Options used by ucal_getTimeZoneOffsetFromLocal and BasicTimeZone::getOffsetFromLocal() to specify ho...
Definition: ucal.h:1627
virtual UBool operator==(const TimeZone &that) const
Returns true if the two TimeZones are equal.
virtual void getOffsetFromLocal(UDate date, UTimeZoneLocalOption nonExistingTimeOpt, UTimeZoneLocalOption duplicatedTimeOpt, int32_t &rawOffset, int32_t &dstOffset, UErrorCode &status) const
Get time zone offsets from local wall time.
double UDate
Date and Time data type.
Definition: utypes.h:203
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
static UClassID getStaticClassID(void)
Return the class ID for this class.
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
C++ API: ICU TimeZone base class.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
TimeZoneRule is a class representing a rule for time zone.
Definition: tzrule.h:36
InitialTimeZoneRule represents a time zone rule representing a time zone effective from the beginning...
Definition: tzrule.h:202
TimeMode
TimeMode is used, together with a millisecond offset after midnight, to specify a rule transition tim...
Definition: simpletz.h:79
virtual UBool hasSameRules(const TimeZone &other) const
Returns true if this zone has the same rule and offset as another zone.
BasicTimeZone & operator=(const BasicTimeZone &)=default
Copy assignment.
virtual int32_t getDSTSavings() const
Returns the amount of time to be added to local standard time to get local wall clock time...
TimeZoneTransition is a class representing a time zone transition.
Definition: tztrans.h:35
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
BasicTimeZone is an abstract class extending TimeZone.
Definition: basictz.h:38
SimpleTimeZone is a concrete subclass of TimeZone that represents a time zone for use with a Gregoria...
Definition: simpletz.h:65
virtual void setRawOffset(int32_t offsetMillis)=0
Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local time...
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
virtual void getTimeZoneRules(const InitialTimeZoneRule *&initial, const TimeZoneRule *trsrules[], int32_t &trscount, UErrorCode &status) const =0
Gets the InitialTimeZoneRule and the set of TimeZoneRule which represent time transitions for this ti...
Basic definitions for ICU, for both C and C++ APIs.
virtual BasicTimeZone * clone() const =0
Clones this object polymorphically.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition &result) const =0
Gets the first time zone transition after the base time.
virtual int32_t countTransitionRules(UErrorCode &status) const =0
Returns the number of TimeZoneRules which represents time transitions, for this time zone...
virtual int32_t getRawOffset(void) const =0
Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add to GMT to get local ti...
virtual UBool inDaylightTime(UDate date, UErrorCode &status) const =0
Queries if the given date is in daylight savings time in this time zone.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269