SimpleTimeZone
TimeZone
* When specifying daylight-savings-time begin and end dates, use a negative value for * dayOfWeekInMonth to indicate that SimpleTimeZone should * count from the end of the month backwards. For example, if Daylight Savings * Time starts or ends at the last Sunday a month, use dayOfWeekInMonth = -1 * along with dayOfWeek = UCAL_SUNDAY to specify the rule. * * @see Calendar * @see GregorianCalendar * @see TimeZone * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu */ class U_I18N_API SimpleTimeZone: public BasicTimeZone { public: /** * TimeMode is used, together with a millisecond offset after * midnight, to specify a rule transition time. Most rules * transition at a local wall time, that is, according to the * current time in effect, either standard, or DST. However, some * rules transition at local standard time, and some at a specific * UTC time. Although it might seem that all times could be * converted to wall time, thus eliminating the need for this * parameter, this is not the case. * @stable ICU 2.0 */ enum TimeMode { WALL_TIME = 0, STANDARD_TIME, UTC_TIME }; /** * Copy constructor * @param source the object to be copied. * @stable ICU 2.0 */ SimpleTimeZone(const SimpleTimeZone& source); /** * Default assignment operator * @param right the object to be copied. * @stable ICU 2.0 */ SimpleTimeZone& operator=(const SimpleTimeZone& right); /** * Destructor * @stable ICU 2.0 */ virtual ~SimpleTimeZone(); /** * Returns true if the two TimeZone objects are equal; that is, they have * the same ID, raw GMT offset, and DST rules. * * @param that The SimpleTimeZone object to be compared with. * @return True if the given time zone is equal to this time zone; false * otherwise. * @stable ICU 2.0 */ virtual UBool operator==(const TimeZone& that) const; /** * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID, * and which doesn't observe daylight savings time. Normally you should use * TimeZone::createInstance() to create a TimeZone instead of creating a * SimpleTimeZone directly with this constructor. * * @param rawOffsetGMT The given base time zone offset to GMT. * @param ID The timezone ID which is obtained from * TimeZone.getAvailableIDs. * @stable ICU 2.0 */ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID); /** * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, * and times to start and end daylight savings time. To create a TimeZone that * doesn't observe daylight savings time, don't use this constructor; use * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use * TimeZone.createInstance() to create a TimeZone instead of creating a * SimpleTimeZone directly with this constructor. *
dayOfWeekInMonth
dayOfWeekInMonth = -1
dayOfWeek = UCAL_SUNDAY
* Various types of daylight-savings time rules can be specfied by using different * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a * complete explanation of how these parameters work, see the documentation for * setStartRule(). * * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset * @param ID The new SimpleTimeZone's time zone ID. * @param savingsStartMonth The daylight savings starting month. Month is * 0-based. eg, 0 for January. * @param savingsStartDayOfWeekInMonth The daylight savings starting * day-of-week-in-month. See setStartRule() for a * complete explanation. * @param savingsStartDayOfWeek The daylight savings starting day-of-week. * See setStartRule() for a complete explanation. * @param savingsStartTime The daylight savings starting time, expressed as the * number of milliseconds after midnight. * @param savingsEndMonth The daylight savings ending month. Month is * 0-based. eg, 0 for January. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. * See setStartRule() for a complete explanation. * @param savingsEndDayOfWeek The daylight savings ending day-of-week. * See setStartRule() for a complete explanation. * @param savingsEndTime The daylight savings ending time, expressed as the * number of milliseconds after midnight. * @param status An UErrorCode to receive the status. * @stable ICU 2.0 */ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, UErrorCode& status); /** * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, * and times to start and end daylight savings time. To create a TimeZone that * doesn't observe daylight savings time, don't use this constructor; use * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use * TimeZone.createInstance() to create a TimeZone instead of creating a * SimpleTimeZone directly with this constructor. *
* Various types of daylight-savings time rules can be specfied by using different * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a * complete explanation of how these parameters work, see the documentation for * setStartRule(). * * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset * @param ID The new SimpleTimeZone's time zone ID. * @param savingsStartMonth The daylight savings starting month. Month is * 0-based. eg, 0 for January. * @param savingsStartDayOfWeekInMonth The daylight savings starting * day-of-week-in-month. See setStartRule() for a * complete explanation. * @param savingsStartDayOfWeek The daylight savings starting day-of-week. * See setStartRule() for a complete explanation. * @param savingsStartTime The daylight savings starting time, expressed as the * number of milliseconds after midnight. * @param savingsEndMonth The daylight savings ending month. Month is * 0-based. eg, 0 for January. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. * See setStartRule() for a complete explanation. * @param savingsEndDayOfWeek The daylight savings ending day-of-week. * See setStartRule() for a complete explanation. * @param savingsEndTime The daylight savings ending time, expressed as the * number of milliseconds after midnight. * @param savingsDST The number of milliseconds added to standard time * to get DST time. Default is one hour. * @param status An UErrorCode to receive the status. * @stable ICU 2.0 */ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, int32_t savingsDST, UErrorCode& status); /** * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, * and times to start and end daylight savings time. To create a TimeZone that * doesn't observe daylight savings time, don't use this constructor; use * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use * TimeZone.createInstance() to create a TimeZone instead of creating a * SimpleTimeZone directly with this constructor. *
* Various types of daylight-savings time rules can be specfied by using different * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a * complete explanation of how these parameters work, see the documentation for * setStartRule(). * * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset * @param ID The new SimpleTimeZone's time zone ID. * @param savingsStartMonth The daylight savings starting month. Month is * 0-based. eg, 0 for January. * @param savingsStartDayOfWeekInMonth The daylight savings starting * day-of-week-in-month. See setStartRule() for a * complete explanation. * @param savingsStartDayOfWeek The daylight savings starting day-of-week. * See setStartRule() for a complete explanation. * @param savingsStartTime The daylight savings starting time, expressed as the * number of milliseconds after midnight. * @param savingsStartTimeMode Whether the start time is local wall time, local * standard time, or UTC time. Default is local wall time. * @param savingsEndMonth The daylight savings ending month. Month is * 0-based. eg, 0 for January. * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. * See setStartRule() for a complete explanation. * @param savingsEndDayOfWeek The daylight savings ending day-of-week. * See setStartRule() for a complete explanation. * @param savingsEndTime The daylight savings ending time, expressed as the * number of milliseconds after midnight. * @param savingsEndTimeMode Whether the end time is local wall time, local * standard time, or UTC time. Default is local wall time. * @param savingsDST The number of milliseconds added to standard time * to get DST time. Default is one hour. * @param status An UErrorCode to receive the status. * @stable ICU 2.0 */ SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, int8_t savingsStartDayOfWeek, int32_t savingsStartTime, TimeMode savingsStartTimeMode, int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode, int32_t savingsDST, UErrorCode& status); /** * Sets the daylight savings starting year, that is, the year this time zone began * observing its specified daylight savings time rules. The time zone is considered * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't * support historical daylight-savings-time rules. * @param year the daylight savings starting year. * @stable ICU 2.0 */ void setStartYear(int32_t year); /** * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings * Time starts at the second Sunday in March, at 2 AM in standard time. * Therefore, you can set the start rule by calling: * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000); * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate * the exact starting date. Their exact meaning depend on their respective signs, * allowing various types of rules to be constructed, as follows: *
* setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000); *
TimeZoneRule
InitialTimeZoneRule
* . Base* polymorphic_pointer = createPolymorphicObject(); * . if (polymorphic_pointer->getDynamicClassID() == * . Derived::getStaticClassID()) ... *
* Upon entry, the day of week variables may be zero or * negative, in order to indicate special modes. The day of month * variables may also be negative. *
* Upon exit, the mode variables will be * set, and the day of week and day of month variables will be positive. *
* This method also recognizes a startDay or endDay of zero as indicating * no DST. */ void decodeRules(UErrorCode& status); void decodeStartRule(UErrorCode& status); void decodeEndRule(UErrorCode& status); int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts int32_t startTime; TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends int32_t endTime; int32_t startYear; // the year these DST rules took effect int32_t rawOffset; // the TimeZone's raw GMT offset UBool useDaylight; // flag indicating whether this TimeZone uses DST static const int8_t STATICMONTHLENGTH[12]; // lengths of the months EMode startMode, endMode; // flags indicating what kind of rules the DST rules are /** * A positive value indicating the amount of time saved during DST in ms. * Typically one hour; sometimes 30 minutes. */ int32_t dstSavings; /* Private for BasicTimeZone implementation */ void checkTransitionRules(UErrorCode& status) const; void initTransitionRules(UErrorCode& status); void clearTransitionRules(void); void deleteTransitionRules(void); UBool transitionRulesInitialized; InitialTimeZoneRule* initialRule; TimeZoneTransition* firstTransition; AnnualTimeZoneRule* stdRule; AnnualTimeZoneRule* dstRule; }; inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, int32_t time, UErrorCode& status) { setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); } inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status) { setStartRule(month, dayOfMonth, time, WALL_TIME, status); } inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, int32_t time, UBool after, UErrorCode& status) { setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); } inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, int32_t time, UErrorCode& status) { setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); } inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status) { setEndRule(month, dayOfMonth, time, WALL_TIME, status); } inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, int32_t time, UBool after, UErrorCode& status) { setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); } inline void SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef, int32_t& dstOffsetRef, UErrorCode& ec) const { TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec); } U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif // _SIMPLETZ