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