+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
-* Copyright (C) {1997-2003}, International Business Machines Corporation and others. All Rights Reserved.
-* *
-********************************************************************************
-*
-* File SIMPLETZ.H
-*
-* Modification History:
-*
-* Date Name Description
-* 04/21/97 aliu Overhauled header.
-* 08/10/98 stephen JDK 1.2 sync
-* Added setStartRule() / setEndRule() overloads
-* Added hasSameRules()
-* 09/02/98 stephen Added getOffset(monthLen)
-* Changed getOffset() to take UErrorCode
-* 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
-* 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
-* methods that take TimeMode. Added to docs.
-********************************************************************************
-*/
+ ********************************************************************************
+ * Copyright (C) 1997-2013, International Business Machines *
+ * Corporation and others. All Rights Reserved. *
+ ********************************************************************************
+ *
+ * File SIMPLETZ.H
+ *
+ * Modification History:
+ *
+ * Date Name Description
+ * 04/21/97 aliu Overhauled header.
+ * 08/10/98 stephen JDK 1.2 sync
+ * Added setStartRule() / setEndRule() overloads
+ * Added hasSameRules()
+ * 09/02/98 stephen Added getOffset(monthLen)
+ * Changed getOffset() to take UErrorCode
+ * 07/09/99 stephen Removed millisPerHour (unused, for HP compiler)
+ * 12/02/99 aliu Added TimeMode and constructor and setStart/EndRule
+ * methods that take TimeMode. Added to docs.
+ ********************************************************************************
+ */
#ifndef SIMPLETZ_H
#define SIMPLETZ_H
#include "unicode/utypes.h"
+/**
+ * \file
+ * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
+ */
+
#if !UCONFIG_NO_FORMATTING
-#include "unicode/timezone.h"
-
-struct StandardZone;
-struct DSTZone;
+#include "unicode/basictz.h"
+#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
-class TimeZone;
+// forward declaration
+class InitialTimeZoneRule;
+class TimeZoneTransition;
+class AnnualTimeZoneRule;
/**
* <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
* <P>
* When specifying daylight-savings-time begin and end dates, use a negative value for
* <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
- * count from the end of the month backwards. For example, in the U.S., Daylight Savings
- * Time ends at the last (dayOfWeekInMonth = -1) Sunday in October, at 2 AM in standard
- * time.
+ * count from the end of the month backwards. For example, if Daylight Savings
+ * Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
+ * along with <code>dayOfWeek = UCAL_SUNDAY</code> 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 TimeZone {
+class U_I18N_API SimpleTimeZone: public BasicTimeZone {
public:
/**
/**
* Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
- * Time starts at the first Sunday in April, at 2 AM in standard time.
+ * Time starts at the second Sunday in March, at 2 AM in standard time.
* Therefore, you can set the start rule by calling:
- * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
+ * 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:<ul>
+ * allowing various types of rules to be constructed, as follows:
+ * <ul>
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
* day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
- * of the month).
+ * of the month).</li>
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
* the day of week in the month counting backward from the end of the month.
- * (e.g., (-1, MONDAY) is the last Monday in the month)
+ * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
* specifies the day of the month, regardless of what day of the week it is.
- * (e.g., (10, 0) is the tenth day of the month)
+ * (e.g., (10, 0) is the tenth day of the month)</li>
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
* specifies the day of the month counting backward from the end of the
* month, regardless of what day of the week it is (e.g., (-2, 0) is the
- * next-to-last day of the month).
+ * next-to-last day of the month).</li>
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
* first specified day of the week on or after the specfied day of the month.
* (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
- * [or the 15th itself if the 15th is a Sunday].)
+ * [or the 15th itself if the 15th is a Sunday].)</li>
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
* last specified day of the week on or before the specified day of the month.
* (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
- * [or the 20th itself if the 20th is a Tuesday].)</ul>
+ * [or the 20th itself if the 20th is a Tuesday].)</li>
+ * </ul>
* @param month the daylight savings starting month. Month is 0-based.
* eg, 0 for January.
* @param dayOfWeekInMonth the daylight savings starting
int32_t time, UErrorCode& status);
/**
* Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
- * Time starts at the first Sunday in April, at 2 AM in standard time.
+ * Time starts at the second Sunday in March, at 2 AM in standard time.
* Therefore, you can set the start rule by calling:
- * setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000);
+ * 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:<ul>
+ * allowing various types of rules to be constructed, as follows:
+ * <ul>
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
* day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
- * of the month).
+ * of the month).</li>
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
* the day of week in the month counting backward from the end of the month.
- * (e.g., (-1, MONDAY) is the last Monday in the month)
+ * (e.g., (-1, MONDAY) is the last Monday in the month)</li>
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
* specifies the day of the month, regardless of what day of the week it is.
- * (e.g., (10, 0) is the tenth day of the month)
+ * (e.g., (10, 0) is the tenth day of the month)</li>
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
* specifies the day of the month counting backward from the end of the
* month, regardless of what day of the week it is (e.g., (-2, 0) is the
- * next-to-last day of the month).
+ * next-to-last day of the month).</li>
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
* first specified day of the week on or after the specfied day of the month.
* (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
- * [or the 15th itself if the 15th is a Sunday].)
+ * [or the 15th itself if the 15th is a Sunday].)</li>
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
* last specified day of the week on or before the specified day of the month.
* (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
- * [or the 20th itself if the 20th is a Tuesday].)</ul>
+ * [or the 20th itself if the 20th is a Tuesday].)</li>
+ * </ul>
* @param month the daylight savings starting month. Month is 0-based.
* eg, 0 for January.
* @param dayOfWeekInMonth the daylight savings starting
int32_t time, TimeMode mode, UBool after, UErrorCode& status);
/**
- * Sets the daylight savings ending rule. For example, in the U.S., Daylight
+ * Sets the daylight savings ending rule. For example, if Daylight
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
* Therefore, you can set the end rule by calling:
* <pre>
- * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
+ * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
* </pre>
* Various other types of rules can be specified by manipulating the dayOfWeek
* and dayOfWeekInMonth parameters. For complete details, see the documentation
int32_t time, UErrorCode& status);
/**
- * Sets the daylight savings ending rule. For example, in the U.S., Daylight
+ * Sets the daylight savings ending rule. For example, if Daylight
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
* Therefore, you can set the end rule by calling:
* <pre>
- * . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000);
+ * setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
* </pre>
* Various other types of rules can be specified by manipulating the dayOfWeek
* and dayOfWeekInMonth parameters. For complete details, see the documentation
int32_t monthLength, int32_t prevMonthLength,
UErrorCode& status) const;
+ /**
+ * Redeclared TimeZone method. This implementation simply calls
+ * the base class method, which otherwise would be hidden.
+ * @stable ICU 2.8
+ */
+ virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
+ int32_t& dstOffset, UErrorCode& ec) const;
+
+ /**
+ * Get time zone offsets from local wall time.
+ * @internal
+ */
+ virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
+ int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const;
+
/**
* Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
* to GMT to get local time, before taking daylight savings time into account).
* are in effect. A positive number, typically one hour (3600000).
* @stable ICU 2.0
*/
- int32_t getDSTSavings(void) const;
+ virtual int32_t getDSTSavings(void) const;
/**
* Queries if this TimeZone uses Daylight Savings Time.
*/
virtual TimeZone* clone(void) const;
+ /**
+ * Gets the first time zone transition after the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the first transition after the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Gets the most recent time zone transition before the base time.
+ * @param base The base time.
+ * @param inclusive Whether the base time is inclusive or not.
+ * @param result Receives the most recent transition before the base time.
+ * @return TRUE if the transition is found.
+ * @stable ICU 3.8
+ */
+ virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const;
+
+ /**
+ * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
+ * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
+ * <code>InitialTimeZoneRule</code>. The return value range is 0 or any positive value.
+ * @param status Receives error status code.
+ * @return The number of <code>TimeZoneRule</code>s representing time transitions.
+ * @stable ICU 3.8
+ */
+ virtual int32_t countTransitionRules(UErrorCode& status) const;
+
+ /**
+ * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
+ * which represent time transitions for this time zone. On successful return,
+ * the argument initial points to non-NULL <code>InitialTimeZoneRule</code> and
+ * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
+ * instances up to the size specified by trscount. The results are referencing the
+ * rule instance held by this time zone instance. Therefore, after this time zone
+ * is destructed, they are no longer available.
+ * @param initial Receives the initial timezone rule
+ * @param trsrules Receives the timezone transition rules
+ * @param trscount On input, specify the size of the array 'transitions' receiving
+ * the timezone transition rules. On output, actual number of
+ * rules filled in the array will be set.
+ * @param status Receives error status code.
+ * @stable ICU 3.8
+ */
+ virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
+ const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const;
+
+
public:
/**
* @return The class ID for all objects of this class.
* @stable ICU 2.0
*/
- static UClassID getStaticClassID(void);
+ static UClassID U_EXPORT2 getStaticClassID(void);
private:
/**
DOW_LE_DOM_MODE
};
- friend class TimeZone; // for access to these 2 constructors:
-
SimpleTimeZone(); // default constructor not implemented
- /**
- * Construct from memory-mapped data.
- */
- SimpleTimeZone(const StandardZone& stdZone, const UnicodeString& id);
- SimpleTimeZone(const DSTZone& dstZone, const UnicodeString& id);
-
/**
* Internal construction method.
* @param rawOffsetGMT The new SimpleTimeZone's raw GMT offset
* @param endTime the time DST ends
* @param endTimeMode 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
+ * @param dstSavings The number of milliseconds added to standard time
* to get DST time. Default is one hour.
* @param status An UErrorCode to receive the status.
*/
void decodeStartRule(UErrorCode& status);
void decodeEndRule(UErrorCode& status);
- static const char fgClassID;
-
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
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
+ static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
EMode startMode, endMode; // flags indicating what kind of rules the DST rules are
/**
* Typically one hour; sometimes 30 minutes.
*/
int32_t dstSavings;
-};
-inline UClassID
-SimpleTimeZone::getStaticClassID(void)
-{ return (UClassID)&fgClassID; }
-
-inline UClassID
-SimpleTimeZone::getDynamicClassID(void) const
-{ return SimpleTimeZone::getStaticClassID(); }
+ /* 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,
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 // U_SHOW_CPLUSPLUS_API
#endif /* #if !UCONFIG_NO_FORMATTING */