SimpleTimeZone
TimeZone
54 * When specifying daylight-savings-time begin and end dates, use a negative value for 55 * dayOfWeekInMonth to indicate that SimpleTimeZone should 56 * count from the end of the month backwards. For example, if Daylight Savings 57 * Time starts or ends at the last Sunday a month, use dayOfWeekInMonth = -1 58 * along with dayOfWeek = UCAL_SUNDAY to specify the rule. 59 * 60 * @see Calendar 61 * @see GregorianCalendar 62 * @see TimeZone 63 * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu 64 */ 65 class U_I18N_API SimpleTimeZone: public BasicTimeZone { 66 public: 67 68 /** 69 * TimeMode is used, together with a millisecond offset after 70 * midnight, to specify a rule transition time. Most rules 71 * transition at a local wall time, that is, according to the 72 * current time in effect, either standard, or DST. However, some 73 * rules transition at local standard time, and some at a specific 74 * UTC time. Although it might seem that all times could be 75 * converted to wall time, thus eliminating the need for this 76 * parameter, this is not the case. 77 * @stable ICU 2.0 78 */ 79 enum TimeMode { 80 WALL_TIME = 0, 81 STANDARD_TIME, 82 UTC_TIME 83 }; 84 85 /** 86 * Copy constructor 87 * @param source the object to be copied. 88 * @stable ICU 2.0 89 */ 90 SimpleTimeZone(const SimpleTimeZone& source); 91 92 /** 93 * Default assignment operator 94 * @param right the object to be copied. 95 * @stable ICU 2.0 96 */ 97 SimpleTimeZone& operator=(const SimpleTimeZone& right); 98 99 /** 100 * Destructor 101 * @stable ICU 2.0 102 */ 103 virtual ~SimpleTimeZone(); 104 105 /** 106 * Returns true if the two TimeZone objects are equal; that is, they have 107 * the same ID, raw GMT offset, and DST rules. 108 * 109 * @param that The SimpleTimeZone object to be compared with. 110 * @return true if the given time zone is equal to this time zone; false 111 * otherwise. 112 * @stable ICU 2.0 113 */ 114 virtual bool operator==(const TimeZone& that) const override; 115 116 /** 117 * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID, 118 * and which doesn't observe daylight savings time. Normally you should use 119 * TimeZone::createInstance() to create a TimeZone instead of creating a 120 * SimpleTimeZone directly with this constructor. 121 * 122 * @param rawOffsetGMT The given base time zone offset to GMT. 123 * @param ID The timezone ID which is obtained from 124 * TimeZone.getAvailableIDs. 125 * @stable ICU 2.0 126 */ 127 SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID); 128 129 /** 130 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, 131 * and times to start and end daylight savings time. To create a TimeZone that 132 * doesn't observe daylight savings time, don't use this constructor; use 133 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use 134 * TimeZone.createInstance() to create a TimeZone instead of creating a 135 * SimpleTimeZone directly with this constructor. 136 *
dayOfWeekInMonth
dayOfWeekInMonth = -1
dayOfWeek = UCAL_SUNDAY
137 * Various types of daylight-savings time rules can be specified by using different 138 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a 139 * complete explanation of how these parameters work, see the documentation for 140 * setStartRule(). 141 * 142 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset 143 * @param ID The new SimpleTimeZone's time zone ID. 144 * @param savingsStartMonth The daylight savings starting month. Month is 145 * 0-based. eg, 0 for January. 146 * @param savingsStartDayOfWeekInMonth The daylight savings starting 147 * day-of-week-in-month. See setStartRule() for a 148 * complete explanation. 149 * @param savingsStartDayOfWeek The daylight savings starting day-of-week. 150 * See setStartRule() for a complete explanation. 151 * @param savingsStartTime The daylight savings starting time, expressed as the 152 * number of milliseconds after midnight. 153 * @param savingsEndMonth The daylight savings ending month. Month is 154 * 0-based. eg, 0 for January. 155 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. 156 * See setStartRule() for a complete explanation. 157 * @param savingsEndDayOfWeek The daylight savings ending day-of-week. 158 * See setStartRule() for a complete explanation. 159 * @param savingsEndTime The daylight savings ending time, expressed as the 160 * number of milliseconds after midnight. 161 * @param status An UErrorCode to receive the status. 162 * @stable ICU 2.0 163 */ 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); 170 /** 171 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, 172 * and times to start and end daylight savings time. To create a TimeZone that 173 * doesn't observe daylight savings time, don't use this constructor; use 174 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use 175 * TimeZone.createInstance() to create a TimeZone instead of creating a 176 * SimpleTimeZone directly with this constructor. 177 *
178 * Various types of daylight-savings time rules can be specified by using different 179 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a 180 * complete explanation of how these parameters work, see the documentation for 181 * setStartRule(). 182 * 183 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset 184 * @param ID The new SimpleTimeZone's time zone ID. 185 * @param savingsStartMonth The daylight savings starting month. Month is 186 * 0-based. eg, 0 for January. 187 * @param savingsStartDayOfWeekInMonth The daylight savings starting 188 * day-of-week-in-month. See setStartRule() for a 189 * complete explanation. 190 * @param savingsStartDayOfWeek The daylight savings starting day-of-week. 191 * See setStartRule() for a complete explanation. 192 * @param savingsStartTime The daylight savings starting time, expressed as the 193 * number of milliseconds after midnight. 194 * @param savingsEndMonth The daylight savings ending month. Month is 195 * 0-based. eg, 0 for January. 196 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. 197 * See setStartRule() for a complete explanation. 198 * @param savingsEndDayOfWeek The daylight savings ending day-of-week. 199 * See setStartRule() for a complete explanation. 200 * @param savingsEndTime The daylight savings ending time, expressed as the 201 * number of milliseconds after midnight. 202 * @param savingsDST The number of milliseconds added to standard time 203 * to get DST time. Default is one hour. 204 * @param status An UErrorCode to receive the status. 205 * @stable ICU 2.0 206 */ 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 214 /** 215 * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, 216 * and times to start and end daylight savings time. To create a TimeZone that 217 * doesn't observe daylight savings time, don't use this constructor; use 218 * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use 219 * TimeZone.createInstance() to create a TimeZone instead of creating a 220 * SimpleTimeZone directly with this constructor. 221 *
222 * Various types of daylight-savings time rules can be specified by using different 223 * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a 224 * complete explanation of how these parameters work, see the documentation for 225 * setStartRule(). 226 * 227 * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset 228 * @param ID The new SimpleTimeZone's time zone ID. 229 * @param savingsStartMonth The daylight savings starting month. Month is 230 * 0-based. eg, 0 for January. 231 * @param savingsStartDayOfWeekInMonth The daylight savings starting 232 * day-of-week-in-month. See setStartRule() for a 233 * complete explanation. 234 * @param savingsStartDayOfWeek The daylight savings starting day-of-week. 235 * See setStartRule() for a complete explanation. 236 * @param savingsStartTime The daylight savings starting time, expressed as the 237 * number of milliseconds after midnight. 238 * @param savingsStartTimeMode Whether the start time is local wall time, local 239 * standard time, or UTC time. Default is local wall time. 240 * @param savingsEndMonth The daylight savings ending month. Month is 241 * 0-based. eg, 0 for January. 242 * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. 243 * See setStartRule() for a complete explanation. 244 * @param savingsEndDayOfWeek The daylight savings ending day-of-week. 245 * See setStartRule() for a complete explanation. 246 * @param savingsEndTime The daylight savings ending time, expressed as the 247 * number of milliseconds after midnight. 248 * @param savingsEndTimeMode Whether the end time is local wall time, local 249 * standard time, or UTC time. Default is local wall time. 250 * @param savingsDST The number of milliseconds added to standard time 251 * to get DST time. Default is one hour. 252 * @param status An UErrorCode to receive the status. 253 * @stable ICU 2.0 254 */ 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 263 /** 264 * Sets the daylight savings starting year, that is, the year this time zone began 265 * observing its specified daylight savings time rules. The time zone is considered 266 * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't 267 * support historical daylight-savings-time rules. 268 * @param year the daylight savings starting year. 269 * @stable ICU 2.0 270 */ 271 void setStartYear(int32_t year); 272 273 /** 274 * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings 275 * Time starts at the second Sunday in March, at 2 AM in standard time. 276 * Therefore, you can set the start rule by calling: 277 * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000); 278 * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate 279 * the exact starting date. Their exact meaning depend on their respective signs, 280 * allowing various types of rules to be constructed, as follows: 281 *
437 * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000); 438 *
462 * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000); 463 *
TimeZoneRule
InitialTimeZoneRule
782 * . Base* polymorphic_pointer = createPolymorphicObject(); 783 * . if (polymorphic_pointer->getDynamicClassID() == 784 * . Derived::getStaticClassID()) ... 785 *
851 * Upon entry, the day of week variables may be zero or 852 * negative, in order to indicate special modes. The day of month 853 * variables may also be negative. 854 *
855 * Upon exit, the mode variables will be 856 * set, and the day of week and day of month variables will be positive. 857 *
858 * This method also recognizes a startDay or endDay of zero as indicating 859 * no DST. 860 */ 861 void decodeRules(UErrorCode& status); 862 void decodeStartRule(UErrorCode& status); 863 void decodeEndRule(UErrorCode& status); 864 865 int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts 866 int32_t startTime; 867 TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode 868 int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends 869 int32_t endTime; 870 int32_t startYear; // the year these DST rules took effect 871 int32_t rawOffset; // the TimeZone's raw GMT offset 872 UBool useDaylight; // flag indicating whether this TimeZone uses DST 873 static const int8_t STATICMONTHLENGTH[12]; // lengths of the months 874 EMode startMode, endMode; // flags indicating what kind of rules the DST rules are 875 876 /** 877 * A positive value indicating the amount of time saved during DST in ms. 878 * Typically one hour; sometimes 30 minutes. 879 */ 880 int32_t dstSavings; 881 882 /* Private for BasicTimeZone implementation */ 883 void checkTransitionRules(UErrorCode& status) const; 884 void initTransitionRules(UErrorCode& status); 885 void clearTransitionRules(void); 886 void deleteTransitionRules(void); 887 UBool transitionRulesInitialized; 888 InitialTimeZoneRule* initialRule; 889 TimeZoneTransition* firstTransition; 890 AnnualTimeZoneRule* stdRule; 891 AnnualTimeZoneRule* dstRule; 892 }; 893 894 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth, 895 int32_t dayOfWeek, 896 int32_t time, UErrorCode& status) { 897 setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); 898 } 899 900 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, 901 int32_t time, 902 UErrorCode& status) { 903 setStartRule(month, dayOfMonth, time, WALL_TIME, status); 904 } 905 906 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, 907 int32_t dayOfWeek, 908 int32_t time, UBool after, UErrorCode& status) { 909 setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); 910 } 911 912 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth, 913 int32_t dayOfWeek, 914 int32_t time, UErrorCode& status) { 915 setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); 916 } 917 918 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, 919 int32_t time, UErrorCode& status) { 920 setEndRule(month, dayOfMonth, time, WALL_TIME, status); 921 } 922 923 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, 924 int32_t time, UBool after, UErrorCode& status) { 925 setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); 926 } 927 928 inline void 929 SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef, 930 int32_t& dstOffsetRef, UErrorCode& ec) const { 931 TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec); 932 } 933 934 U_NAMESPACE_END 935 936 #endif /* #if !UCONFIG_NO_FORMATTING */ 937 938 #endif /* U_SHOW_CPLUSPLUS_API */ 939 940 #endif // _SIMPLETZ