jpayne@69: // © 2016 and later: Unicode, Inc. and others.
jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html
jpayne@69: /*
jpayne@69: ********************************************************************************
jpayne@69: * Copyright (C) 1997-2013, International Business Machines *
jpayne@69: * Corporation and others. All Rights Reserved. *
jpayne@69: ********************************************************************************
jpayne@69: *
jpayne@69: * File SIMPLETZ.H
jpayne@69: *
jpayne@69: * Modification History:
jpayne@69: *
jpayne@69: * Date Name Description
jpayne@69: * 04/21/97 aliu Overhauled header.
jpayne@69: * 08/10/98 stephen JDK 1.2 sync
jpayne@69: * Added setStartRule() / setEndRule() overloads
jpayne@69: * Added hasSameRules()
jpayne@69: * 09/02/98 stephen Added getOffset(monthLen)
jpayne@69: * Changed getOffset() to take UErrorCode
jpayne@69: * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
jpayne@69: * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
jpayne@69: * methods that take TimeMode. Added to docs.
jpayne@69: ********************************************************************************
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef SIMPLETZ_H
jpayne@69: #define SIMPLETZ_H
jpayne@69:
jpayne@69: #include "unicode/utypes.h"
jpayne@69:
jpayne@69: #if U_SHOW_CPLUSPLUS_API
jpayne@69:
jpayne@69: /**
jpayne@69: * \file
jpayne@69: * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
jpayne@69: */
jpayne@69:
jpayne@69: #if !UCONFIG_NO_FORMATTING
jpayne@69:
jpayne@69: #include "unicode/basictz.h"
jpayne@69:
jpayne@69: U_NAMESPACE_BEGIN
jpayne@69:
jpayne@69: // forward declaration
jpayne@69: class InitialTimeZoneRule;
jpayne@69: class TimeZoneTransition;
jpayne@69: class AnnualTimeZoneRule;
jpayne@69:
jpayne@69: /**
jpayne@69: * SimpleTimeZone
is a concrete subclass of TimeZone
jpayne@69: * that represents a time zone for use with a Gregorian calendar. This
jpayne@69: * class does not handle historical changes.
jpayne@69: *
jpayne@69: * When specifying daylight-savings-time begin and end dates, use a negative value for
jpayne@69: * dayOfWeekInMonth
to indicate that SimpleTimeZone
should
jpayne@69: * count from the end of the month backwards. For example, if Daylight Savings
jpayne@69: * Time starts or ends at the last Sunday a month, use dayOfWeekInMonth = -1
jpayne@69: * along with dayOfWeek = UCAL_SUNDAY
to specify the rule.
jpayne@69: *
jpayne@69: * @see Calendar
jpayne@69: * @see GregorianCalendar
jpayne@69: * @see TimeZone
jpayne@69: * @author D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
jpayne@69: */
jpayne@69: class U_I18N_API SimpleTimeZone: public BasicTimeZone {
jpayne@69: public:
jpayne@69:
jpayne@69: /**
jpayne@69: * TimeMode is used, together with a millisecond offset after
jpayne@69: * midnight, to specify a rule transition time. Most rules
jpayne@69: * transition at a local wall time, that is, according to the
jpayne@69: * current time in effect, either standard, or DST. However, some
jpayne@69: * rules transition at local standard time, and some at a specific
jpayne@69: * UTC time. Although it might seem that all times could be
jpayne@69: * converted to wall time, thus eliminating the need for this
jpayne@69: * parameter, this is not the case.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: enum TimeMode {
jpayne@69: WALL_TIME = 0,
jpayne@69: STANDARD_TIME,
jpayne@69: UTC_TIME
jpayne@69: };
jpayne@69:
jpayne@69: /**
jpayne@69: * Copy constructor
jpayne@69: * @param source the object to be copied.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: SimpleTimeZone(const SimpleTimeZone& source);
jpayne@69:
jpayne@69: /**
jpayne@69: * Default assignment operator
jpayne@69: * @param right the object to be copied.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: SimpleTimeZone& operator=(const SimpleTimeZone& right);
jpayne@69:
jpayne@69: /**
jpayne@69: * Destructor
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual ~SimpleTimeZone();
jpayne@69:
jpayne@69: /**
jpayne@69: * Returns true if the two TimeZone objects are equal; that is, they have
jpayne@69: * the same ID, raw GMT offset, and DST rules.
jpayne@69: *
jpayne@69: * @param that The SimpleTimeZone object to be compared with.
jpayne@69: * @return True if the given time zone is equal to this time zone; false
jpayne@69: * otherwise.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UBool operator==(const TimeZone& that) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
jpayne@69: * and which doesn't observe daylight savings time. Normally you should use
jpayne@69: * TimeZone::createInstance() to create a TimeZone instead of creating a
jpayne@69: * SimpleTimeZone directly with this constructor.
jpayne@69: *
jpayne@69: * @param rawOffsetGMT The given base time zone offset to GMT.
jpayne@69: * @param ID The timezone ID which is obtained from
jpayne@69: * TimeZone.getAvailableIDs.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
jpayne@69:
jpayne@69: /**
jpayne@69: * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
jpayne@69: * and times to start and end daylight savings time. To create a TimeZone that
jpayne@69: * doesn't observe daylight savings time, don't use this constructor; use
jpayne@69: * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
jpayne@69: * TimeZone.createInstance() to create a TimeZone instead of creating a
jpayne@69: * SimpleTimeZone directly with this constructor.
jpayne@69: *
jpayne@69: * Various types of daylight-savings time rules can be specfied by using different jpayne@69: * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a jpayne@69: * complete explanation of how these parameters work, see the documentation for jpayne@69: * setStartRule(). jpayne@69: * jpayne@69: * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset jpayne@69: * @param ID The new SimpleTimeZone's time zone ID. jpayne@69: * @param savingsStartMonth The daylight savings starting month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsStartDayOfWeekInMonth The daylight savings starting jpayne@69: * day-of-week-in-month. See setStartRule() for a jpayne@69: * complete explanation. jpayne@69: * @param savingsStartDayOfWeek The daylight savings starting day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsStartTime The daylight savings starting time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param savingsEndMonth The daylight savings ending month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndDayOfWeek The daylight savings ending day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndTime The daylight savings ending time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, jpayne@69: int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, jpayne@69: int8_t savingsStartDayOfWeek, int32_t savingsStartTime, jpayne@69: int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, jpayne@69: int8_t savingsEndDayOfWeek, int32_t savingsEndTime, jpayne@69: UErrorCode& status); jpayne@69: /** jpayne@69: * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, jpayne@69: * and times to start and end daylight savings time. To create a TimeZone that jpayne@69: * doesn't observe daylight savings time, don't use this constructor; use jpayne@69: * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use jpayne@69: * TimeZone.createInstance() to create a TimeZone instead of creating a jpayne@69: * SimpleTimeZone directly with this constructor. jpayne@69: *
jpayne@69: * Various types of daylight-savings time rules can be specfied by using different jpayne@69: * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a jpayne@69: * complete explanation of how these parameters work, see the documentation for jpayne@69: * setStartRule(). jpayne@69: * jpayne@69: * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset jpayne@69: * @param ID The new SimpleTimeZone's time zone ID. jpayne@69: * @param savingsStartMonth The daylight savings starting month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsStartDayOfWeekInMonth The daylight savings starting jpayne@69: * day-of-week-in-month. See setStartRule() for a jpayne@69: * complete explanation. jpayne@69: * @param savingsStartDayOfWeek The daylight savings starting day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsStartTime The daylight savings starting time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param savingsEndMonth The daylight savings ending month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndDayOfWeek The daylight savings ending day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndTime The daylight savings ending time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param savingsDST The number of milliseconds added to standard time jpayne@69: * to get DST time. Default is one hour. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, jpayne@69: int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, jpayne@69: int8_t savingsStartDayOfWeek, int32_t savingsStartTime, jpayne@69: int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, jpayne@69: int8_t savingsEndDayOfWeek, int32_t savingsEndTime, jpayne@69: int32_t savingsDST, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, jpayne@69: * and times to start and end daylight savings time. To create a TimeZone that jpayne@69: * doesn't observe daylight savings time, don't use this constructor; use jpayne@69: * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use jpayne@69: * TimeZone.createInstance() to create a TimeZone instead of creating a jpayne@69: * SimpleTimeZone directly with this constructor. jpayne@69: *
jpayne@69: * Various types of daylight-savings time rules can be specfied by using different jpayne@69: * values for startDay and startDayOfWeek and endDay and endDayOfWeek. For a jpayne@69: * complete explanation of how these parameters work, see the documentation for jpayne@69: * setStartRule(). jpayne@69: * jpayne@69: * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset jpayne@69: * @param ID The new SimpleTimeZone's time zone ID. jpayne@69: * @param savingsStartMonth The daylight savings starting month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsStartDayOfWeekInMonth The daylight savings starting jpayne@69: * day-of-week-in-month. See setStartRule() for a jpayne@69: * complete explanation. jpayne@69: * @param savingsStartDayOfWeek The daylight savings starting day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsStartTime The daylight savings starting time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param savingsStartTimeMode Whether the start time is local wall time, local jpayne@69: * standard time, or UTC time. Default is local wall time. jpayne@69: * @param savingsEndMonth The daylight savings ending month. Month is jpayne@69: * 0-based. eg, 0 for January. jpayne@69: * @param savingsEndDayOfWeekInMonth The daylight savings ending day-of-week-in-month. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndDayOfWeek The daylight savings ending day-of-week. jpayne@69: * See setStartRule() for a complete explanation. jpayne@69: * @param savingsEndTime The daylight savings ending time, expressed as the jpayne@69: * number of milliseconds after midnight. jpayne@69: * @param savingsEndTimeMode Whether the end time is local wall time, local jpayne@69: * standard time, or UTC time. Default is local wall time. jpayne@69: * @param savingsDST The number of milliseconds added to standard time jpayne@69: * to get DST time. Default is one hour. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID, jpayne@69: int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth, jpayne@69: int8_t savingsStartDayOfWeek, int32_t savingsStartTime, jpayne@69: TimeMode savingsStartTimeMode, jpayne@69: int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth, jpayne@69: int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode, jpayne@69: int32_t savingsDST, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the daylight savings starting year, that is, the year this time zone began jpayne@69: * observing its specified daylight savings time rules. The time zone is considered jpayne@69: * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't jpayne@69: * support historical daylight-savings-time rules. jpayne@69: * @param year the daylight savings starting year. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setStartYear(int32_t year); jpayne@69: jpayne@69: /** jpayne@69: * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings jpayne@69: * Time starts at the second Sunday in March, at 2 AM in standard time. jpayne@69: * Therefore, you can set the start rule by calling: jpayne@69: * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000); jpayne@69: * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate jpayne@69: * the exact starting date. Their exact meaning depend on their respective signs, jpayne@69: * allowing various types of rules to be constructed, as follows: jpayne@69: *
jpayne@69: * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000); jpayne@69: *jpayne@69: * Various other types of rules can be specified by manipulating the dayOfWeek jpayne@69: * and dayOfWeekInMonth parameters. For complete details, see the documentation jpayne@69: * for setStartRule(). jpayne@69: * jpayne@69: * @param month the daylight savings ending month. Month is 0-based. jpayne@69: * eg, 0 for January. jpayne@69: * @param dayOfWeekInMonth the daylight savings ending jpayne@69: * day-of-week-in-month. See setStartRule() for a complete explanation. jpayne@69: * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule() jpayne@69: * for a complete explanation. jpayne@69: * @param time the daylight savings ending time. Please see the member jpayne@69: * description for an example. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, jpayne@69: int32_t time, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the daylight savings ending rule. For example, if Daylight jpayne@69: * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time. jpayne@69: * Therefore, you can set the end rule by calling: jpayne@69: *
jpayne@69: * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000); jpayne@69: *jpayne@69: * Various other types of rules can be specified by manipulating the dayOfWeek jpayne@69: * and dayOfWeekInMonth parameters. For complete details, see the documentation jpayne@69: * for setStartRule(). jpayne@69: * jpayne@69: * @param month the daylight savings ending month. Month is 0-based. jpayne@69: * eg, 0 for January. jpayne@69: * @param dayOfWeekInMonth the daylight savings ending jpayne@69: * day-of-week-in-month. See setStartRule() for a complete explanation. jpayne@69: * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule() jpayne@69: * for a complete explanation. jpayne@69: * @param time the daylight savings ending time. Please see the member jpayne@69: * description for an example. jpayne@69: * @param mode whether the time is local wall time, local standard time, jpayne@69: * or UTC time. Default is local wall time. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek, jpayne@69: int32_t time, TimeMode mode, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the DST end rule to a fixed date within a month. jpayne@69: * jpayne@69: * @param month The month in which this rule occurs (0-based). jpayne@69: * @param dayOfMonth The date in that month (1-based). jpayne@69: * @param time The time of that day (number of millis after midnight) jpayne@69: * when DST ends in local wall time, which is daylight jpayne@69: * time in this case. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the DST end rule to a fixed date within a month. jpayne@69: * jpayne@69: * @param month The month in which this rule occurs (0-based). jpayne@69: * @param dayOfMonth The date in that month (1-based). jpayne@69: * @param time The time of that day (number of millis after midnight) jpayne@69: * when DST ends in local wall time, which is daylight jpayne@69: * time in this case. jpayne@69: * @param mode whether the time is local wall time, local standard time, jpayne@69: * or UTC time. Default is local wall time. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, jpayne@69: TimeMode mode, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the DST end rule to a weekday before or after a give date within jpayne@69: * a month, e.g., the first Monday on or after the 8th. jpayne@69: * jpayne@69: * @param month The month in which this rule occurs (0-based). jpayne@69: * @param dayOfMonth A date within that month (1-based). jpayne@69: * @param dayOfWeek The day of the week on which this rule occurs. jpayne@69: * @param time The time of that day (number of millis after midnight) jpayne@69: * when DST ends in local wall time, which is daylight jpayne@69: * time in this case. jpayne@69: * @param after If true, this rule selects the first dayOfWeek on jpayne@69: * or after dayOfMonth. If false, this rule selects jpayne@69: * the last dayOfWeek on or before dayOfMonth. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, jpayne@69: int32_t time, UBool after, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Sets the DST end rule to a weekday before or after a give date within jpayne@69: * a month, e.g., the first Monday on or after the 8th. jpayne@69: * jpayne@69: * @param month The month in which this rule occurs (0-based). jpayne@69: * @param dayOfMonth A date within that month (1-based). jpayne@69: * @param dayOfWeek The day of the week on which this rule occurs. jpayne@69: * @param time The time of that day (number of millis after midnight) jpayne@69: * when DST ends in local wall time, which is daylight jpayne@69: * time in this case. jpayne@69: * @param mode whether the time is local wall time, local standard time, jpayne@69: * or UTC time. Default is local wall time. jpayne@69: * @param after If true, this rule selects the first dayOfWeek on jpayne@69: * or after dayOfMonth. If false, this rule selects jpayne@69: * the last dayOfWeek on or before dayOfMonth. jpayne@69: * @param status An UErrorCode jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, jpayne@69: int32_t time, TimeMode mode, UBool after, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time in this time zone, taking daylight savings time into jpayne@69: * account) as of a particular reference date. The reference date is used to determine jpayne@69: * whether daylight savings time is in effect and needs to be figured into the offset jpayne@69: * that is returned (in other words, what is the adjusted GMT offset in this time zone jpayne@69: * at this particular date and time?). For the time zones produced by createTimeZone(), jpayne@69: * the reference data is specified according to the Gregorian calendar, and the date jpayne@69: * and time fields are in GMT, NOT local time. jpayne@69: * jpayne@69: * @param era The reference date's era jpayne@69: * @param year The reference date's year jpayne@69: * @param month The reference date's month (0-based; 0 is January) jpayne@69: * @param day The reference date's day-in-month (1-based) jpayne@69: * @param dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) jpayne@69: * @param millis The reference date's milliseconds in day, UTT (NOT local time). jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @return The offset in milliseconds to add to GMT to get local time. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, jpayne@69: uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the time zone offset, for current date, modified in case of jpayne@69: * daylight savings. This is the offset to add *to* UTC to get local time. jpayne@69: * @param era the era of the given date. jpayne@69: * @param year the year in the given date. jpayne@69: * @param month the month in the given date. jpayne@69: * Month is 0-based. e.g., 0 for January. jpayne@69: * @param day the day-in-month of the given date. jpayne@69: * @param dayOfWeek the day-of-week of the given date. jpayne@69: * @param milliseconds the millis in day in standard local time. jpayne@69: * @param monthLength the length of the given month in days. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @return the offset to add *to* GMT to get local time. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, jpayne@69: uint8_t dayOfWeek, int32_t milliseconds, jpayne@69: int32_t monthLength, UErrorCode& status) const; jpayne@69: /** jpayne@69: * Gets the time zone offset, for current date, modified in case of jpayne@69: * daylight savings. This is the offset to add *to* UTC to get local time. jpayne@69: * @param era the era of the given date. jpayne@69: * @param year the year in the given date. jpayne@69: * @param month the month in the given date. jpayne@69: * Month is 0-based. e.g., 0 for January. jpayne@69: * @param day the day-in-month of the given date. jpayne@69: * @param dayOfWeek the day-of-week of the given date. jpayne@69: * @param milliseconds the millis in day in standard local time. jpayne@69: * @param monthLength the length of the given month in days. jpayne@69: * @param prevMonthLength length of the previous month in days. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @return the offset to add *to* GMT to get local time. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day, jpayne@69: uint8_t dayOfWeek, int32_t milliseconds, jpayne@69: int32_t monthLength, int32_t prevMonthLength, jpayne@69: UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Redeclared TimeZone method. This implementation simply calls jpayne@69: * the base class method, which otherwise would be hidden. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: virtual void getOffset(UDate date, UBool local, int32_t& rawOffset, jpayne@69: int32_t& dstOffset, UErrorCode& ec) const; jpayne@69: jpayne@69: /** jpayne@69: * Get time zone offsets from local wall time. jpayne@69: * @internal jpayne@69: */ jpayne@69: virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt, jpayne@69: int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time, before taking daylight savings time into account). jpayne@69: * jpayne@69: * @return The TimeZone's raw GMT offset. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getRawOffset(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add jpayne@69: * to GMT to get local time, before taking daylight savings time into account). jpayne@69: * jpayne@69: * @param offsetMillis The new raw GMT offset for this time zone. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual void setRawOffset(int32_t offsetMillis); jpayne@69: jpayne@69: /** jpayne@69: * Sets the amount of time in ms that the clock is advanced during DST. jpayne@69: * @param millisSavedDuringDST the number of milliseconds the time is jpayne@69: * advanced with respect to standard time when the daylight savings rules jpayne@69: * are in effect. Typically one hour (+3600000). The amount could be negative, jpayne@69: * but not 0. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the amount of time in ms that the clock is advanced during DST. jpayne@69: * @return the number of milliseconds the time is jpayne@69: * advanced with respect to standard time when the daylight savings rules jpayne@69: * are in effect. Typically one hour (+3600000). The amount could be negative, jpayne@69: * but not 0. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual int32_t getDSTSavings(void) const; jpayne@69: jpayne@69: /** jpayne@69: * Queries if this TimeZone uses Daylight Savings Time. jpayne@69: * jpayne@69: * @return True if this TimeZone uses Daylight Savings Time; false otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual UBool useDaylightTime(void) const; jpayne@69: jpayne@69: #ifndef U_FORCE_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Returns true if the given date is within the period when daylight savings time jpayne@69: * is in effect; false otherwise. If the TimeZone doesn't observe daylight savings jpayne@69: * time, this functions always returns false. jpayne@69: * This method is wasteful since it creates a new GregorianCalendar and jpayne@69: * deletes it each time it is called. This is a deprecated method jpayne@69: * and provided only for Java compatibility. jpayne@69: * jpayne@69: * @param date The date to test. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: * @return true if the given date is in Daylight Savings Time; jpayne@69: * false otherwise. jpayne@69: * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead. jpayne@69: */ jpayne@69: virtual UBool inDaylightTime(UDate date, UErrorCode& status) const; jpayne@69: #endif // U_FORCE_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * Return true if this zone has the same rules and offset as another zone. jpayne@69: * @param other the TimeZone object to be compared with jpayne@69: * @return true if the given zone has the same rules and offset as this one jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: UBool hasSameRules(const TimeZone& other) const; jpayne@69: jpayne@69: /** jpayne@69: * Clones TimeZone objects polymorphically. Clients are responsible for deleting jpayne@69: * the TimeZone object cloned. jpayne@69: * jpayne@69: * @return A new copy of this TimeZone object. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: virtual SimpleTimeZone* clone() const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the first time zone transition after the base time. jpayne@69: * @param base The base time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives the first transition after the base time. jpayne@69: * @return TRUE if the transition is found. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Gets the most recent time zone transition before the base time. jpayne@69: * @param base The base time. jpayne@69: * @param inclusive Whether the base time is inclusive or not. jpayne@69: * @param result Receives the most recent transition before the base time. jpayne@69: * @return TRUE if the transition is found. jpayne@69: * @stable ICU 3.8 jpayne@69: */ jpayne@69: virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const; jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of
TimeZoneRule
s which represents time transitions,
jpayne@69: * for this time zone, that is, all TimeZoneRule
s for this time zone except
jpayne@69: * InitialTimeZoneRule
. The return value range is 0 or any positive value.
jpayne@69: * @param status Receives error status code.
jpayne@69: * @return The number of TimeZoneRule
s representing time transitions.
jpayne@69: * @stable ICU 3.8
jpayne@69: */
jpayne@69: virtual int32_t countTransitionRules(UErrorCode& status) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Gets the InitialTimeZoneRule
and the set of TimeZoneRule
jpayne@69: * which represent time transitions for this time zone. On successful return,
jpayne@69: * the argument initial points to non-NULL InitialTimeZoneRule
and
jpayne@69: * the array trsrules is filled with 0 or multiple TimeZoneRule
jpayne@69: * instances up to the size specified by trscount. The results are referencing the
jpayne@69: * rule instance held by this time zone instance. Therefore, after this time zone
jpayne@69: * is destructed, they are no longer available.
jpayne@69: * @param initial Receives the initial timezone rule
jpayne@69: * @param trsrules Receives the timezone transition rules
jpayne@69: * @param trscount On input, specify the size of the array 'transitions' receiving
jpayne@69: * the timezone transition rules. On output, actual number of
jpayne@69: * rules filled in the array will be set.
jpayne@69: * @param status Receives error status code.
jpayne@69: * @stable ICU 3.8
jpayne@69: */
jpayne@69: virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
jpayne@69: const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
jpayne@69:
jpayne@69:
jpayne@69: public:
jpayne@69:
jpayne@69: /**
jpayne@69: * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
jpayne@69: * override. This method is to implement a simple version of RTTI, since not all C++
jpayne@69: * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
jpayne@69: * this method.
jpayne@69: *
jpayne@69: * @return The class ID for this object. All objects of a given class have the
jpayne@69: * same class ID. Objects of other classes have different class IDs.
jpayne@69: * @stable ICU 2.0
jpayne@69: */
jpayne@69: virtual UClassID getDynamicClassID(void) const;
jpayne@69:
jpayne@69: /**
jpayne@69: * Return the class ID for this class. This is useful only for comparing to a return
jpayne@69: * value from getDynamicClassID(). For example:
jpayne@69: * jpayne@69: * . Base* polymorphic_pointer = createPolymorphicObject(); jpayne@69: * . if (polymorphic_pointer->getDynamicClassID() == jpayne@69: * . Derived::getStaticClassID()) ... jpayne@69: *jpayne@69: * @return The class ID for all objects of this class. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: static UClassID U_EXPORT2 getStaticClassID(void); jpayne@69: jpayne@69: private: jpayne@69: /** jpayne@69: * Constants specifying values of startMode and endMode. jpayne@69: */ jpayne@69: enum EMode jpayne@69: { jpayne@69: DOM_MODE = 1, jpayne@69: DOW_IN_MONTH_MODE, jpayne@69: DOW_GE_DOM_MODE, jpayne@69: DOW_LE_DOM_MODE jpayne@69: }; jpayne@69: jpayne@69: SimpleTimeZone(); // default constructor not implemented jpayne@69: jpayne@69: /** jpayne@69: * Internal construction method. jpayne@69: * @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset jpayne@69: * @param startMonth the month DST starts jpayne@69: * @param startDay the day DST starts jpayne@69: * @param startDayOfWeek the DOW DST starts jpayne@69: * @param startTime the time DST starts jpayne@69: * @param startTimeMode Whether the start time is local wall time, local jpayne@69: * standard time, or UTC time. Default is local wall time. jpayne@69: * @param endMonth the month DST ends jpayne@69: * @param endDay the day DST ends jpayne@69: * @param endDayOfWeek the DOW DST ends jpayne@69: * @param endTime the time DST ends jpayne@69: * @param endTimeMode Whether the end time is local wall time, local jpayne@69: * standard time, or UTC time. Default is local wall time. jpayne@69: * @param dstSavings The number of milliseconds added to standard time jpayne@69: * to get DST time. Default is one hour. jpayne@69: * @param status An UErrorCode to receive the status. jpayne@69: */ jpayne@69: void construct(int32_t rawOffsetGMT, jpayne@69: int8_t startMonth, int8_t startDay, int8_t startDayOfWeek, jpayne@69: int32_t startTime, TimeMode startTimeMode, jpayne@69: int8_t endMonth, int8_t endDay, int8_t endDayOfWeek, jpayne@69: int32_t endTime, TimeMode endTimeMode, jpayne@69: int32_t dstSavings, UErrorCode& status); jpayne@69: jpayne@69: /** jpayne@69: * Compare a given date in the year to a rule. Return 1, 0, or -1, depending jpayne@69: * on whether the date is after, equal to, or before the rule date. The jpayne@69: * millis are compared directly against the ruleMillis, so any jpayne@69: * standard-daylight adjustments must be handled by the caller. jpayne@69: * jpayne@69: * @return 1 if the date is after the rule date, -1 if the date is before jpayne@69: * the rule date, or 0 if the date is equal to the rule date. jpayne@69: */ jpayne@69: static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen, jpayne@69: int8_t dayOfMonth, jpayne@69: int8_t dayOfWeek, int32_t millis, int32_t millisDelta, jpayne@69: EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek, jpayne@69: int8_t ruleDay, int32_t ruleMillis); jpayne@69: jpayne@69: /** jpayne@69: * Given a set of encoded rules in startDay and startDayOfMonth, decode jpayne@69: * them and set the startMode appropriately. Do the same for endDay and jpayne@69: * endDayOfMonth. jpayne@69: *
jpayne@69: * Upon entry, the day of week variables may be zero or jpayne@69: * negative, in order to indicate special modes. The day of month jpayne@69: * variables may also be negative. jpayne@69: *
jpayne@69: * Upon exit, the mode variables will be jpayne@69: * set, and the day of week and day of month variables will be positive. jpayne@69: *
jpayne@69: * This method also recognizes a startDay or endDay of zero as indicating jpayne@69: * no DST. jpayne@69: */ jpayne@69: void decodeRules(UErrorCode& status); jpayne@69: void decodeStartRule(UErrorCode& status); jpayne@69: void decodeEndRule(UErrorCode& status); jpayne@69: jpayne@69: int8_t startMonth, startDay, startDayOfWeek; // the month, day, DOW, and time DST starts jpayne@69: int32_t startTime; jpayne@69: TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode jpayne@69: int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends jpayne@69: int32_t endTime; jpayne@69: int32_t startYear; // the year these DST rules took effect jpayne@69: int32_t rawOffset; // the TimeZone's raw GMT offset jpayne@69: UBool useDaylight; // flag indicating whether this TimeZone uses DST jpayne@69: static const int8_t STATICMONTHLENGTH[12]; // lengths of the months jpayne@69: EMode startMode, endMode; // flags indicating what kind of rules the DST rules are jpayne@69: jpayne@69: /** jpayne@69: * A positive value indicating the amount of time saved during DST in ms. jpayne@69: * Typically one hour; sometimes 30 minutes. jpayne@69: */ jpayne@69: int32_t dstSavings; jpayne@69: jpayne@69: /* Private for BasicTimeZone implementation */ jpayne@69: void checkTransitionRules(UErrorCode& status) const; jpayne@69: void initTransitionRules(UErrorCode& status); jpayne@69: void clearTransitionRules(void); jpayne@69: void deleteTransitionRules(void); jpayne@69: UBool transitionRulesInitialized; jpayne@69: InitialTimeZoneRule* initialRule; jpayne@69: TimeZoneTransition* firstTransition; jpayne@69: AnnualTimeZoneRule* stdRule; jpayne@69: AnnualTimeZoneRule* dstRule; jpayne@69: }; jpayne@69: jpayne@69: inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth, jpayne@69: int32_t dayOfWeek, jpayne@69: int32_t time, UErrorCode& status) { jpayne@69: setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); jpayne@69: } jpayne@69: jpayne@69: inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, jpayne@69: int32_t time, jpayne@69: UErrorCode& status) { jpayne@69: setStartRule(month, dayOfMonth, time, WALL_TIME, status); jpayne@69: } jpayne@69: jpayne@69: inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth, jpayne@69: int32_t dayOfWeek, jpayne@69: int32_t time, UBool after, UErrorCode& status) { jpayne@69: setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); jpayne@69: } jpayne@69: jpayne@69: inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth, jpayne@69: int32_t dayOfWeek, jpayne@69: int32_t time, UErrorCode& status) { jpayne@69: setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status); jpayne@69: } jpayne@69: jpayne@69: inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, jpayne@69: int32_t time, UErrorCode& status) { jpayne@69: setEndRule(month, dayOfMonth, time, WALL_TIME, status); jpayne@69: } jpayne@69: jpayne@69: inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek, jpayne@69: int32_t time, UBool after, UErrorCode& status) { jpayne@69: setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status); jpayne@69: } jpayne@69: jpayne@69: inline void jpayne@69: SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef, jpayne@69: int32_t& dstOffsetRef, UErrorCode& ec) const { jpayne@69: TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec); jpayne@69: } jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* #if !UCONFIG_NO_FORMATTING */ jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif // _SIMPLETZ