Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:08

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004  ********************************************************************************
0005  * Copyright (C) 1997-2013, International Business Machines                     *
0006  * Corporation and others. All Rights Reserved.                                 *
0007  ********************************************************************************
0008  *
0009  * File SIMPLETZ.H
0010  *
0011  * Modification History:
0012  *
0013  *   Date        Name        Description
0014  *   04/21/97    aliu        Overhauled header.
0015  *   08/10/98    stephen     JDK 1.2 sync
0016  *                           Added setStartRule() / setEndRule() overloads
0017  *                           Added hasSameRules()
0018  *   09/02/98    stephen     Added getOffset(monthLen)
0019  *                           Changed getOffset() to take UErrorCode
0020  *   07/09/99    stephen     Removed millisPerHour (unused, for HP compiler)
0021  *   12/02/99    aliu        Added TimeMode and constructor and setStart/EndRule
0022  *                           methods that take TimeMode. Added to docs.
0023  ********************************************************************************
0024  */
0025 
0026 #ifndef SIMPLETZ_H
0027 #define SIMPLETZ_H
0028 
0029 #include "unicode/utypes.h"
0030 
0031 #if U_SHOW_CPLUSPLUS_API
0032 
0033 /**
0034  * \file 
0035  * \brief C++ API: SimpleTimeZone is a concrete subclass of TimeZone.
0036  */
0037  
0038 #if !UCONFIG_NO_FORMATTING
0039 
0040 #include "unicode/basictz.h"
0041 
0042 U_NAMESPACE_BEGIN
0043 
0044 // forward declaration
0045 class InitialTimeZoneRule;
0046 class TimeZoneTransition;
0047 class AnnualTimeZoneRule;
0048 
0049 /**
0050  * <code>SimpleTimeZone</code> is a concrete subclass of <code>TimeZone</code>
0051  * that represents a time zone for use with a Gregorian calendar. This
0052  * class does not handle historical changes.
0053  * <P>
0054  * When specifying daylight-savings-time begin and end dates, use a negative value for
0055  * <code>dayOfWeekInMonth</code> to indicate that <code>SimpleTimeZone</code> should
0056  * count from the end of the month backwards. For example, if Daylight Savings
0057  * Time starts or ends at the last Sunday a month, use <code>dayOfWeekInMonth = -1</code>
0058  * along with <code>dayOfWeek = UCAL_SUNDAY</code> to specify the rule.
0059  *
0060  * @see      Calendar
0061  * @see      GregorianCalendar
0062  * @see      TimeZone
0063  * @author   D. Goldsmith, Mark Davis, Chen-Lieh Huang, Alan Liu
0064  */
0065 class U_I18N_API SimpleTimeZone: public BasicTimeZone {
0066 public:
0067 
0068     /**
0069      * TimeMode is used, together with a millisecond offset after
0070      * midnight, to specify a rule transition time.  Most rules
0071      * transition at a local wall time, that is, according to the
0072      * current time in effect, either standard, or DST.  However, some
0073      * rules transition at local standard time, and some at a specific
0074      * UTC time.  Although it might seem that all times could be
0075      * converted to wall time, thus eliminating the need for this
0076      * parameter, this is not the case.
0077      * @stable ICU 2.0
0078      */
0079     enum TimeMode {
0080         WALL_TIME = 0,
0081         STANDARD_TIME,
0082         UTC_TIME
0083     };
0084 
0085     /**
0086      * Copy constructor
0087      * @param source the object to be copied.
0088      * @stable ICU 2.0
0089      */
0090     SimpleTimeZone(const SimpleTimeZone& source);
0091 
0092     /**
0093      * Default assignment operator
0094      * @param right    the object to be copied.
0095      * @stable ICU 2.0
0096      */
0097     SimpleTimeZone& operator=(const SimpleTimeZone& right);
0098 
0099     /**
0100      * Destructor
0101      * @stable ICU 2.0
0102      */
0103     virtual ~SimpleTimeZone();
0104 
0105     /**
0106      * Returns true if the two TimeZone objects are equal; that is, they have
0107      * the same ID, raw GMT offset, and DST rules.
0108      *
0109      * @param that  The SimpleTimeZone object to be compared with.
0110      * @return      true if the given time zone is equal to this time zone; false
0111      *              otherwise.
0112      * @stable ICU 2.0
0113      */
0114     virtual bool operator==(const TimeZone& that) const override;
0115 
0116     /**
0117      * Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID,
0118      * and which doesn't observe daylight savings time.  Normally you should use
0119      * TimeZone::createInstance() to create a TimeZone instead of creating a
0120      * SimpleTimeZone directly with this constructor.
0121      *
0122      * @param rawOffsetGMT  The given base time zone offset to GMT.
0123      * @param ID         The timezone ID which is obtained from
0124      *                   TimeZone.getAvailableIDs.
0125      * @stable ICU 2.0
0126      */
0127     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
0128 
0129     /**
0130      * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
0131      * and times to start and end daylight savings time. To create a TimeZone that
0132      * doesn't observe daylight savings time, don't use this constructor; use
0133      * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
0134      * TimeZone.createInstance() to create a TimeZone instead of creating a
0135      * SimpleTimeZone directly with this constructor.
0136      * <P>
0137      * Various types of daylight-savings time rules can be specified by using different
0138      * values for startDay and startDayOfWeek and endDay and endDayOfWeek.  For a
0139      * complete explanation of how these parameters work, see the documentation for
0140      * setStartRule().
0141      *
0142      * @param rawOffsetGMT      The new SimpleTimeZone's raw GMT offset
0143      * @param ID                The new SimpleTimeZone's time zone ID.
0144      * @param savingsStartMonth The daylight savings starting month. Month is
0145      *                          0-based. eg, 0 for January.
0146      * @param savingsStartDayOfWeekInMonth   The daylight savings starting
0147      *                          day-of-week-in-month. See setStartRule() for a
0148      *                          complete explanation.
0149      * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
0150      *                          See setStartRule() for a complete explanation.
0151      * @param savingsStartTime  The daylight savings starting time, expressed as the
0152      *                          number of milliseconds after midnight.
0153      * @param savingsEndMonth   The daylight savings ending month. Month is
0154      *                          0-based. eg, 0 for January.
0155      * @param savingsEndDayOfWeekInMonth     The daylight savings ending day-of-week-in-month.
0156      *                          See setStartRule() for a complete explanation.
0157      * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
0158      *                          See setStartRule() for a complete explanation.
0159      * @param savingsEndTime    The daylight savings ending time, expressed as the
0160      *                          number of milliseconds after midnight.
0161      * @param status            An UErrorCode to receive the status.
0162      * @stable ICU 2.0
0163      */
0164     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
0165         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
0166         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
0167         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
0168         int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
0169         UErrorCode& status);
0170     /**
0171      * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
0172      * and times to start and end daylight savings time. To create a TimeZone that
0173      * doesn't observe daylight savings time, don't use this constructor; use
0174      * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
0175      * TimeZone.createInstance() to create a TimeZone instead of creating a
0176      * SimpleTimeZone directly with this constructor.
0177      * <P>
0178      * Various types of daylight-savings time rules can be specified by using different
0179      * values for startDay and startDayOfWeek and endDay and endDayOfWeek.  For a
0180      * complete explanation of how these parameters work, see the documentation for
0181      * setStartRule().
0182      *
0183      * @param rawOffsetGMT      The new SimpleTimeZone's raw GMT offset
0184      * @param ID                The new SimpleTimeZone's time zone ID.
0185      * @param savingsStartMonth The daylight savings starting month. Month is
0186      *                          0-based. eg, 0 for January.
0187      * @param savingsStartDayOfWeekInMonth   The daylight savings starting
0188      *                          day-of-week-in-month. See setStartRule() for a
0189      *                          complete explanation.
0190      * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
0191      *                          See setStartRule() for a complete explanation.
0192      * @param savingsStartTime  The daylight savings starting time, expressed as the
0193      *                          number of milliseconds after midnight.
0194      * @param savingsEndMonth   The daylight savings ending month. Month is
0195      *                          0-based. eg, 0 for January.
0196      * @param savingsEndDayOfWeekInMonth     The daylight savings ending day-of-week-in-month.
0197      *                          See setStartRule() for a complete explanation.
0198      * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
0199      *                          See setStartRule() for a complete explanation.
0200      * @param savingsEndTime    The daylight savings ending time, expressed as the
0201      *                          number of milliseconds after midnight.
0202      * @param savingsDST        The number of milliseconds added to standard time
0203      *                          to get DST time. Default is one hour.
0204      * @param status            An UErrorCode to receive the status.
0205      * @stable ICU 2.0
0206      */
0207     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
0208         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
0209         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
0210         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
0211         int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
0212         int32_t savingsDST, UErrorCode& status);
0213 
0214     /**
0215      * Construct a SimpleTimeZone with the given raw GMT offset, time zone ID,
0216      * and times to start and end daylight savings time. To create a TimeZone that
0217      * doesn't observe daylight savings time, don't use this constructor; use
0218      * SimpleTimeZone(rawOffset, ID) instead. Normally, you should use
0219      * TimeZone.createInstance() to create a TimeZone instead of creating a
0220      * SimpleTimeZone directly with this constructor.
0221      * <P>
0222      * Various types of daylight-savings time rules can be specified by using different
0223      * values for startDay and startDayOfWeek and endDay and endDayOfWeek.  For a
0224      * complete explanation of how these parameters work, see the documentation for
0225      * setStartRule().
0226      *
0227      * @param rawOffsetGMT      The new SimpleTimeZone's raw GMT offset
0228      * @param ID                The new SimpleTimeZone's time zone ID.
0229      * @param savingsStartMonth The daylight savings starting month. Month is
0230      *                          0-based. eg, 0 for January.
0231      * @param savingsStartDayOfWeekInMonth   The daylight savings starting
0232      *                          day-of-week-in-month. See setStartRule() for a
0233      *                          complete explanation.
0234      * @param savingsStartDayOfWeek The daylight savings starting day-of-week.
0235      *                          See setStartRule() for a complete explanation.
0236      * @param savingsStartTime  The daylight savings starting time, expressed as the
0237      *                          number of milliseconds after midnight.
0238      * @param savingsStartTimeMode Whether the start time is local wall time, local
0239      *                          standard time, or UTC time. Default is local wall time.
0240      * @param savingsEndMonth   The daylight savings ending month. Month is
0241      *                          0-based. eg, 0 for January.
0242      * @param savingsEndDayOfWeekInMonth     The daylight savings ending day-of-week-in-month.
0243      *                          See setStartRule() for a complete explanation.
0244      * @param savingsEndDayOfWeek The daylight savings ending day-of-week.
0245      *                          See setStartRule() for a complete explanation.
0246      * @param savingsEndTime    The daylight savings ending time, expressed as the
0247      *                          number of milliseconds after midnight.
0248      * @param savingsEndTimeMode Whether the end time is local wall time, local
0249      *                          standard time, or UTC time. Default is local wall time.
0250      * @param savingsDST        The number of milliseconds added to standard time
0251      *                          to get DST time. Default is one hour.
0252      * @param status            An UErrorCode to receive the status.
0253      * @stable ICU 2.0
0254      */
0255     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
0256         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
0257         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
0258         TimeMode savingsStartTimeMode,
0259         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
0260         int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
0261         int32_t savingsDST, UErrorCode& status);
0262 
0263     /**
0264      * Sets the daylight savings starting year, that is, the year this time zone began
0265      * observing its specified daylight savings time rules.  The time zone is considered
0266      * not to observe daylight savings time prior to that year; SimpleTimeZone doesn't
0267      * support historical daylight-savings-time rules.
0268      * @param year the daylight savings starting year.
0269      * @stable ICU 2.0
0270      */
0271     void setStartYear(int32_t year);
0272 
0273     /**
0274      * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
0275      * Time starts at the second Sunday in March, at 2 AM in standard time.
0276      * Therefore, you can set the start rule by calling:
0277      * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
0278      * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
0279      * the exact starting date.  Their exact meaning depend on their respective signs,
0280      * allowing various types of rules to be constructed, as follows:
0281      * <ul>
0282      *   <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
0283      *       day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
0284      *       of the month).</li>
0285      *   <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
0286      *       the day of week in the month counting backward from the end of the month.
0287      *       (e.g., (-1, MONDAY) is the last Monday in the month)</li>
0288      *   <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
0289      *       specifies the day of the month, regardless of what day of the week it is.
0290      *       (e.g., (10, 0) is the tenth day of the month)</li>
0291      *   <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
0292      *       specifies the day of the month counting backward from the end of the
0293      *       month, regardless of what day of the week it is (e.g., (-2, 0) is the
0294      *       next-to-last day of the month).</li>
0295      *   <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
0296      *       first specified day of the week on or after the specified day of the month.
0297      *       (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
0298      *       [or the 15th itself if the 15th is a Sunday].)</li>
0299      *   <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
0300      *       last specified day of the week on or before the specified day of the month.
0301      *       (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
0302      *       [or the 20th itself if the 20th is a Tuesday].)</li>
0303      * </ul>
0304      * @param month the daylight savings starting month. Month is 0-based.
0305      * eg, 0 for January.
0306      * @param dayOfWeekInMonth the daylight savings starting
0307      * day-of-week-in-month. Please see the member description for an example.
0308      * @param dayOfWeek the daylight savings starting day-of-week. Please see
0309      * the member description for an example.
0310      * @param time the daylight savings starting time. Please see the member
0311      * description for an example.
0312      * @param status An UErrorCode
0313      * @stable ICU 2.0
0314      */
0315     void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
0316                       int32_t time, UErrorCode& status);
0317     /**
0318      * Sets the daylight savings starting rule. For example, in the U.S., Daylight Savings
0319      * Time starts at the second Sunday in March, at 2 AM in standard time.
0320      * Therefore, you can set the start rule by calling:
0321      * setStartRule(UCAL_MARCH, 2, UCAL_SUNDAY, 2*60*60*1000);
0322      * The dayOfWeekInMonth and dayOfWeek parameters together specify how to calculate
0323      * the exact starting date.  Their exact meaning depend on their respective signs,
0324      * allowing various types of rules to be constructed, as follows:
0325      * <ul>
0326      *   <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the
0327      *       day of week in the month (e.g., (2, WEDNESDAY) is the second Wednesday
0328      *       of the month).</li>
0329      *   <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they specify
0330      *       the day of week in the month counting backward from the end of the month.
0331      *       (e.g., (-1, MONDAY) is the last Monday in the month)</li>
0332      *   <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, dayOfWeekInMonth
0333      *       specifies the day of the month, regardless of what day of the week it is.
0334      *       (e.g., (10, 0) is the tenth day of the month)</li>
0335      *   <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, dayOfWeekInMonth
0336      *       specifies the day of the month counting backward from the end of the
0337      *       month, regardless of what day of the week it is (e.g., (-2, 0) is the
0338      *       next-to-last day of the month).</li>
0339      *   <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they specify the
0340      *       first specified day of the week on or after the specified day of the month.
0341      *       (e.g., (15, -SUNDAY) is the first Sunday after the 15th of the month
0342      *       [or the 15th itself if the 15th is a Sunday].)</li>
0343      *   <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the
0344      *       last specified day of the week on or before the specified day of the month.
0345      *       (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of the month
0346      *       [or the 20th itself if the 20th is a Tuesday].)</li>
0347      * </ul>
0348      * @param month the daylight savings starting month. Month is 0-based.
0349      * eg, 0 for January.
0350      * @param dayOfWeekInMonth the daylight savings starting
0351      * day-of-week-in-month. Please see the member description for an example.
0352      * @param dayOfWeek the daylight savings starting day-of-week. Please see
0353      * the member description for an example.
0354      * @param time the daylight savings starting time. Please see the member
0355      * description for an example.
0356      * @param mode whether the time is local wall time, local standard time,
0357      * or UTC time. Default is local wall time.
0358      * @param status An UErrorCode
0359      * @stable ICU 2.0
0360      */
0361     void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
0362                       int32_t time, TimeMode mode, UErrorCode& status);
0363 
0364     /**
0365      * Sets the DST start rule to a fixed date within a month.
0366      *
0367      * @param month         The month in which this rule occurs (0-based).
0368      * @param dayOfMonth    The date in that month (1-based).
0369      * @param time          The time of that day (number of millis after midnight)
0370      *                      when DST takes effect in local wall time, which is
0371      *                      standard time in this case.
0372      * @param status An UErrorCode
0373      * @stable ICU 2.0
0374      */
0375     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
0376                       UErrorCode& status);
0377     /**
0378      * Sets the DST start rule to a fixed date within a month.
0379      *
0380      * @param month         The month in which this rule occurs (0-based).
0381      * @param dayOfMonth    The date in that month (1-based).
0382      * @param time          The time of that day (number of millis after midnight)
0383      *                      when DST takes effect in local wall time, which is
0384      *                      standard time in this case.
0385      * @param mode whether the time is local wall time, local standard time,
0386      * or UTC time. Default is local wall time.
0387      * @param status An UErrorCode
0388      * @stable ICU 2.0
0389      */
0390     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
0391                       TimeMode mode, UErrorCode& status);
0392 
0393     /**
0394      * Sets the DST start rule to a weekday before or after a give date within
0395      * a month, e.g., the first Monday on or after the 8th.
0396      *
0397      * @param month         The month in which this rule occurs (0-based).
0398      * @param dayOfMonth    A date within that month (1-based).
0399      * @param dayOfWeek     The day of the week on which this rule occurs.
0400      * @param time          The time of that day (number of millis after midnight)
0401      *                      when DST takes effect in local wall time, which is
0402      *                      standard time in this case.
0403      * @param after         If true, this rule selects the first dayOfWeek on
0404      *                      or after dayOfMonth.  If false, this rule selects
0405      *                      the last dayOfWeek on or before dayOfMonth.
0406      * @param status An UErrorCode
0407      * @stable ICU 2.0
0408      */
0409     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
0410                       int32_t time, UBool after, UErrorCode& status);
0411     /**
0412      * Sets the DST start rule to a weekday before or after a give date within
0413      * a month, e.g., the first Monday on or after the 8th.
0414      *
0415      * @param month         The month in which this rule occurs (0-based).
0416      * @param dayOfMonth    A date within that month (1-based).
0417      * @param dayOfWeek     The day of the week on which this rule occurs.
0418      * @param time          The time of that day (number of millis after midnight)
0419      *                      when DST takes effect in local wall time, which is
0420      *                      standard time in this case.
0421      * @param mode whether the time is local wall time, local standard time,
0422      * or UTC time. Default is local wall time.
0423      * @param after         If true, this rule selects the first dayOfWeek on
0424      *                      or after dayOfMonth.  If false, this rule selects
0425      *                      the last dayOfWeek on or before dayOfMonth.
0426      * @param status An UErrorCode
0427      * @stable ICU 2.0
0428      */
0429     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
0430                       int32_t time, TimeMode mode, UBool after, UErrorCode& status);
0431 
0432     /**
0433      * Sets the daylight savings ending rule. For example, if Daylight
0434      * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
0435      * Therefore, you can set the end rule by calling:
0436      * <pre>
0437      *    setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
0438      * </pre>
0439      * Various other types of rules can be specified by manipulating the dayOfWeek
0440      * and dayOfWeekInMonth parameters.  For complete details, see the documentation
0441      * for setStartRule().
0442      *
0443      * @param month the daylight savings ending month. Month is 0-based.
0444      * eg, 0 for January.
0445      * @param dayOfWeekInMonth the daylight savings ending
0446      * day-of-week-in-month. See setStartRule() for a complete explanation.
0447      * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
0448      * for a complete explanation.
0449      * @param time the daylight savings ending time. Please see the member
0450      * description for an example.
0451      * @param status An UErrorCode
0452      * @stable ICU 2.0
0453      */
0454     void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
0455                     int32_t time, UErrorCode& status);
0456 
0457     /**
0458      * Sets the daylight savings ending rule. For example, if Daylight
0459      * Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard time.
0460      * Therefore, you can set the end rule by calling:
0461      * <pre>
0462      *    setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2*60*60*1000);
0463      * </pre>
0464      * Various other types of rules can be specified by manipulating the dayOfWeek
0465      * and dayOfWeekInMonth parameters.  For complete details, see the documentation
0466      * for setStartRule().
0467      *
0468      * @param month the daylight savings ending month. Month is 0-based.
0469      * eg, 0 for January.
0470      * @param dayOfWeekInMonth the daylight savings ending
0471      * day-of-week-in-month. See setStartRule() for a complete explanation.
0472      * @param dayOfWeek the daylight savings ending day-of-week. See setStartRule()
0473      * for a complete explanation.
0474      * @param time the daylight savings ending time. Please see the member
0475      * description for an example.
0476      * @param mode whether the time is local wall time, local standard time,
0477      * or UTC time. Default is local wall time.
0478      * @param status An UErrorCode
0479      * @stable ICU 2.0
0480      */
0481     void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
0482                     int32_t time, TimeMode mode, UErrorCode& status);
0483 
0484     /**
0485      * Sets the DST end rule to a fixed date within a month.
0486      *
0487      * @param month         The month in which this rule occurs (0-based).
0488      * @param dayOfMonth    The date in that month (1-based).
0489      * @param time          The time of that day (number of millis after midnight)
0490      *                      when DST ends in local wall time, which is daylight
0491      *                      time in this case.
0492      * @param status An UErrorCode
0493      * @stable ICU 2.0
0494      */
0495     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
0496 
0497     /**
0498      * Sets the DST end rule to a fixed date within a month.
0499      *
0500      * @param month         The month in which this rule occurs (0-based).
0501      * @param dayOfMonth    The date in that month (1-based).
0502      * @param time          The time of that day (number of millis after midnight)
0503      *                      when DST ends in local wall time, which is daylight
0504      *                      time in this case.
0505      * @param mode whether the time is local wall time, local standard time,
0506      * or UTC time. Default is local wall time.
0507      * @param status An UErrorCode
0508      * @stable ICU 2.0
0509      */
0510     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
0511                     TimeMode mode, UErrorCode& status);
0512 
0513     /**
0514      * Sets the DST end rule to a weekday before or after a give date within
0515      * a month, e.g., the first Monday on or after the 8th.
0516      *
0517      * @param month         The month in which this rule occurs (0-based).
0518      * @param dayOfMonth    A date within that month (1-based).
0519      * @param dayOfWeek     The day of the week on which this rule occurs.
0520      * @param time          The time of that day (number of millis after midnight)
0521      *                      when DST ends in local wall time, which is daylight
0522      *                      time in this case.
0523      * @param after         If true, this rule selects the first dayOfWeek on
0524      *                      or after dayOfMonth.  If false, this rule selects
0525      *                      the last dayOfWeek on or before dayOfMonth.
0526      * @param status An UErrorCode
0527      * @stable ICU 2.0
0528      */
0529     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
0530                     int32_t time, UBool after, UErrorCode& status);
0531 
0532     /**
0533      * Sets the DST end rule to a weekday before or after a give date within
0534      * a month, e.g., the first Monday on or after the 8th.
0535      *
0536      * @param month         The month in which this rule occurs (0-based).
0537      * @param dayOfMonth    A date within that month (1-based).
0538      * @param dayOfWeek     The day of the week on which this rule occurs.
0539      * @param time          The time of that day (number of millis after midnight)
0540      *                      when DST ends in local wall time, which is daylight
0541      *                      time in this case.
0542      * @param mode whether the time is local wall time, local standard time,
0543      * or UTC time. Default is local wall time.
0544      * @param after         If true, this rule selects the first dayOfWeek on
0545      *                      or after dayOfMonth.  If false, this rule selects
0546      *                      the last dayOfWeek on or before dayOfMonth.
0547      * @param status An UErrorCode
0548      * @stable ICU 2.0
0549      */
0550     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
0551                     int32_t time, TimeMode mode, UBool after, UErrorCode& status);
0552 
0553     /**
0554      * Returns the TimeZone's adjusted GMT offset (i.e., the number of milliseconds to add
0555      * to GMT to get local time in this time zone, taking daylight savings time into
0556      * account) as of a particular reference date.  The reference date is used to determine
0557      * whether daylight savings time is in effect and needs to be figured into the offset
0558      * that is returned (in other words, what is the adjusted GMT offset in this time zone
0559      * at this particular date and time?).  For the time zones produced by createTimeZone(),
0560      * the reference data is specified according to the Gregorian calendar, and the date
0561      * and time fields are in GMT, NOT local time.
0562      *
0563      * @param era        The reference date's era
0564      * @param year       The reference date's year
0565      * @param month      The reference date's month (0-based; 0 is January)
0566      * @param day        The reference date's day-in-month (1-based)
0567      * @param dayOfWeek  The reference date's day-of-week (1-based; 1 is Sunday)
0568      * @param millis     The reference date's milliseconds in day, UTT (NOT local time).
0569      * @param status     An UErrorCode to receive the status.
0570      * @return           The offset in milliseconds to add to GMT to get local time.
0571      * @stable ICU 2.0
0572      */
0573     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
0574                               uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const override;
0575 
0576     /**
0577      * Gets the time zone offset, for current date, modified in case of
0578      * daylight savings. This is the offset to add *to* UTC to get local time.
0579      * @param era the era of the given date.
0580      * @param year the year in the given date.
0581      * @param month the month in the given date.
0582      * Month is 0-based. e.g., 0 for January.
0583      * @param day the day-in-month of the given date.
0584      * @param dayOfWeek the day-of-week of the given date.
0585      * @param milliseconds the millis in day in <em>standard</em> local time.
0586      * @param monthLength the length of the given month in days.
0587      * @param status     An UErrorCode to receive the status.
0588      * @return the offset to add *to* GMT to get local time.
0589      * @stable ICU 2.0
0590      */
0591     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
0592                            uint8_t dayOfWeek, int32_t milliseconds,
0593                            int32_t monthLength, UErrorCode& status) const override;
0594     /**
0595      * Gets the time zone offset, for current date, modified in case of
0596      * daylight savings. This is the offset to add *to* UTC to get local time.
0597      * @param era the era of the given date.
0598      * @param year the year in the given date.
0599      * @param month the month in the given date.
0600      * Month is 0-based. e.g., 0 for January.
0601      * @param day the day-in-month of the given date.
0602      * @param dayOfWeek the day-of-week of the given date.
0603      * @param milliseconds the millis in day in <em>standard</em> local time.
0604      * @param monthLength the length of the given month in days.
0605      * @param prevMonthLength length of the previous month in days.
0606      * @param status     An UErrorCode to receive the status.
0607      * @return the offset to add *to* GMT to get local time.
0608      * @stable ICU 2.0
0609      */
0610     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
0611                               uint8_t dayOfWeek, int32_t milliseconds,
0612                               int32_t monthLength, int32_t prevMonthLength,
0613                               UErrorCode& status) const;
0614 
0615     /**
0616      * Redeclared TimeZone method.  This implementation simply calls
0617      * the base class method, which otherwise would be hidden.
0618      * @stable ICU 2.8
0619      */
0620     virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
0621                            int32_t& dstOffset, UErrorCode& ec) const override;
0622 
0623     /**
0624      * Get time zone offsets from local wall time.
0625      * @stable ICU 69
0626      */
0627     virtual void getOffsetFromLocal(
0628         UDate date, UTimeZoneLocalOption nonExistingTimeOpt,
0629         UTimeZoneLocalOption duplicatedTimeOpt,
0630         int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const override;
0631 
0632     /**
0633      * Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
0634      * to GMT to get local time, before taking daylight savings time into account).
0635      *
0636      * @return   The TimeZone's raw GMT offset.
0637      * @stable ICU 2.0
0638      */
0639     virtual int32_t getRawOffset(void) const override;
0640 
0641     /**
0642      * Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to add
0643      * to GMT to get local time, before taking daylight savings time into account).
0644      *
0645      * @param offsetMillis  The new raw GMT offset for this time zone.
0646      * @stable ICU 2.0
0647      */
0648     virtual void setRawOffset(int32_t offsetMillis) override;
0649 
0650     /**
0651      * Sets the amount of time in ms that the clock is advanced during DST.
0652      * @param millisSavedDuringDST the number of milliseconds the time is
0653      * advanced with respect to standard time when the daylight savings rules
0654      * are in effect. Typically one hour (+3600000). The amount could be negative,
0655      * but not 0.
0656      * @param status  An UErrorCode to receive the status.
0657      * @stable ICU 2.0
0658      */
0659     void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
0660 
0661     /**
0662      * Returns the amount of time in ms that the clock is advanced during DST.
0663      * @return the number of milliseconds the time is
0664      * advanced with respect to standard time when the daylight savings rules
0665      * are in effect. Typically one hour (+3600000). The amount could be negative,
0666      * but not 0.
0667      * @stable ICU 2.0
0668      */
0669     virtual int32_t getDSTSavings(void) const override;
0670 
0671     /**
0672      * Queries if this TimeZone uses Daylight Savings Time.
0673      *
0674      * @return   True if this TimeZone uses Daylight Savings Time; false otherwise.
0675      * @stable ICU 2.0
0676      */
0677     virtual UBool useDaylightTime(void) const override;
0678 
0679 #ifndef U_FORCE_HIDE_DEPRECATED_API
0680     /**
0681      * Returns true if the given date is within the period when daylight savings time
0682      * is in effect; false otherwise.  If the TimeZone doesn't observe daylight savings
0683      * time, this functions always returns false.
0684      * This method is wasteful since it creates a new GregorianCalendar and
0685      * deletes it each time it is called. This is a deprecated method
0686      * and provided only for Java compatibility.
0687      *
0688      * @param date The date to test.
0689      * @param status  An UErrorCode to receive the status.
0690      * @return true if the given date is in Daylight Savings Time;
0691      * false otherwise.
0692      * @deprecated ICU 2.4. Use Calendar::inDaylightTime() instead.
0693      */
0694     virtual UBool inDaylightTime(UDate date, UErrorCode& status) const override;
0695 #endif  // U_FORCE_HIDE_DEPRECATED_API
0696 
0697     /**
0698      * Return true if this zone has the same rules and offset as another zone.
0699      * @param other the TimeZone object to be compared with
0700      * @return true if the given zone has the same rules and offset as this one
0701      * @stable ICU 2.0
0702      */
0703     UBool hasSameRules(const TimeZone& other) const override;
0704 
0705     /**
0706      * Clones TimeZone objects polymorphically. Clients are responsible for deleting
0707      * the TimeZone object cloned.
0708      *
0709      * @return   A new copy of this TimeZone object.
0710      * @stable ICU 2.0
0711      */
0712     virtual SimpleTimeZone* clone() const override;
0713 
0714     /**
0715      * Gets the first time zone transition after the base time.
0716      * @param base      The base time.
0717      * @param inclusive Whether the base time is inclusive or not.
0718      * @param result    Receives the first transition after the base time.
0719      * @return  true if the transition is found.
0720      * @stable ICU 3.8
0721      */
0722     virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
0723 
0724     /**
0725      * Gets the most recent time zone transition before the base time.
0726      * @param base      The base time.
0727      * @param inclusive Whether the base time is inclusive or not.
0728      * @param result    Receives the most recent transition before the base time.
0729      * @return  true if the transition is found.
0730      * @stable ICU 3.8
0731      */
0732     virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const override;
0733 
0734     /**
0735      * Returns the number of <code>TimeZoneRule</code>s which represents time transitions,
0736      * for this time zone, that is, all <code>TimeZoneRule</code>s for this time zone except
0737      * <code>InitialTimeZoneRule</code>.  The return value range is 0 or any positive value.
0738      * @param status    Receives error status code.
0739      * @return The number of <code>TimeZoneRule</code>s representing time transitions.
0740      * @stable ICU 3.8
0741      */
0742     virtual int32_t countTransitionRules(UErrorCode& status) const override;
0743 
0744     /**
0745      * Gets the <code>InitialTimeZoneRule</code> and the set of <code>TimeZoneRule</code>
0746      * which represent time transitions for this time zone.  On successful return,
0747      * the argument initial points to non-nullptr <code>InitialTimeZoneRule</code> and
0748      * the array trsrules is filled with 0 or multiple <code>TimeZoneRule</code>
0749      * instances up to the size specified by trscount.  The results are referencing the
0750      * rule instance held by this time zone instance.  Therefore, after this time zone
0751      * is destructed, they are no longer available.
0752      * @param initial       Receives the initial timezone rule
0753      * @param trsrules      Receives the timezone transition rules
0754      * @param trscount      On input, specify the size of the array 'transitions' receiving
0755      *                      the timezone transition rules.  On output, actual number of
0756      *                      rules filled in the array will be set.
0757      * @param status        Receives error status code.
0758      * @stable ICU 3.8
0759      */
0760     virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
0761         const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) const override;
0762 
0763 
0764 public:
0765 
0766     /**
0767      * Override TimeZone Returns a unique class ID POLYMORPHICALLY. Pure virtual
0768      * override. This method is to implement a simple version of RTTI, since not all C++
0769      * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
0770      * this method.
0771      *
0772      * @return   The class ID for this object. All objects of a given class have the
0773      *           same class ID. Objects of other classes have different class IDs.
0774      * @stable ICU 2.0
0775      */
0776     virtual UClassID getDynamicClassID(void) const override;
0777 
0778     /**
0779      * Return the class ID for this class. This is useful only for comparing to a return
0780      * value from getDynamicClassID(). For example:
0781      * <pre>
0782      * .   Base* polymorphic_pointer = createPolymorphicObject();
0783      * .   if (polymorphic_pointer->getDynamicClassID() ==
0784      * .       Derived::getStaticClassID()) ...
0785      * </pre>
0786      * @return   The class ID for all objects of this class.
0787      * @stable ICU 2.0
0788      */
0789     static UClassID U_EXPORT2 getStaticClassID(void);
0790 
0791 private:
0792     /**
0793      * Constants specifying values of startMode and endMode.
0794      */
0795     enum EMode
0796     {
0797         DOM_MODE = 1,
0798         DOW_IN_MONTH_MODE,
0799         DOW_GE_DOM_MODE,
0800         DOW_LE_DOM_MODE
0801     };
0802 
0803     SimpleTimeZone() = delete; // default constructor not implemented
0804 
0805     /**
0806      * Internal construction method.
0807      * @param rawOffsetGMT    The new SimpleTimeZone's raw GMT offset
0808      * @param startMonth      the month DST starts
0809      * @param startDay        the day DST starts
0810      * @param startDayOfWeek  the DOW DST starts
0811      * @param startTime       the time DST starts
0812      * @param startTimeMode   Whether the start time is local wall time, local
0813      *                        standard time, or UTC time. Default is local wall time.
0814      * @param endMonth        the month DST ends
0815      * @param endDay          the day DST ends
0816      * @param endDayOfWeek    the DOW DST ends
0817      * @param endTime         the time DST ends
0818      * @param endTimeMode     Whether the end time is local wall time, local
0819      *                        standard time, or UTC time. Default is local wall time.
0820      * @param dstSavings      The number of milliseconds added to standard time
0821      *                        to get DST time. Default is one hour.
0822      * @param status          An UErrorCode to receive the status.
0823      */
0824     void construct(int32_t rawOffsetGMT,
0825                    int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
0826                    int32_t startTime, TimeMode startTimeMode,
0827                    int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
0828                    int32_t endTime, TimeMode endTimeMode,
0829                    int32_t dstSavings, UErrorCode& status);
0830 
0831     /**
0832      * Compare a given date in the year to a rule. Return 1, 0, or -1, depending
0833      * on whether the date is after, equal to, or before the rule date. The
0834      * millis are compared directly against the ruleMillis, so any
0835      * standard-daylight adjustments must be handled by the caller.
0836      *
0837      * @return  1 if the date is after the rule date, -1 if the date is before
0838      *          the rule date, or 0 if the date is equal to the rule date.
0839      */
0840     static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
0841                                  int8_t dayOfMonth,
0842                                  int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
0843                                  EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
0844                                  int8_t ruleDay, int32_t ruleMillis);
0845 
0846     /**
0847      * Given a set of encoded rules in startDay and startDayOfMonth, decode
0848      * them and set the startMode appropriately.  Do the same for endDay and
0849      * endDayOfMonth.
0850      * <P>
0851      * Upon entry, the day of week variables may be zero or
0852      * negative, in order to indicate special modes.  The day of month
0853      * variables may also be negative.
0854      * <P>
0855      * Upon exit, the mode variables will be
0856      * set, and the day of week and day of month variables will be positive.
0857      * <P>
0858      * This method also recognizes a startDay or endDay of zero as indicating
0859      * no DST.
0860      */
0861     void decodeRules(UErrorCode& status);
0862     void decodeStartRule(UErrorCode& status);
0863     void decodeEndRule(UErrorCode& status);
0864 
0865     int8_t startMonth, startDay, startDayOfWeek;   // the month, day, DOW, and time DST starts
0866     int32_t startTime;
0867     TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
0868     int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
0869     int32_t endTime;
0870     int32_t startYear;  // the year these DST rules took effect
0871     int32_t rawOffset;  // the TimeZone's raw GMT offset
0872     UBool useDaylight; // flag indicating whether this TimeZone uses DST
0873     static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
0874     EMode startMode, endMode;   // flags indicating what kind of rules the DST rules are
0875 
0876     /**
0877      * A positive value indicating the amount of time saved during DST in ms.
0878      * Typically one hour; sometimes 30 minutes.
0879      */
0880     int32_t dstSavings;
0881 
0882     /* Private for BasicTimeZone implementation */
0883     void checkTransitionRules(UErrorCode& status) const;
0884     void initTransitionRules(UErrorCode& status);
0885     void clearTransitionRules(void);
0886     void deleteTransitionRules(void);
0887     UBool   transitionRulesInitialized;
0888     InitialTimeZoneRule*    initialRule;
0889     TimeZoneTransition*     firstTransition;
0890     AnnualTimeZoneRule*     stdRule;
0891     AnnualTimeZoneRule*     dstRule;
0892 };
0893 
0894 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
0895                                          int32_t dayOfWeek,
0896                                          int32_t time, UErrorCode& status) {
0897     setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
0898 }
0899 
0900 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
0901                                          int32_t time,
0902                                          UErrorCode& status) {
0903     setStartRule(month, dayOfMonth, time, WALL_TIME, status);
0904 }
0905 
0906 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
0907                                          int32_t dayOfWeek,
0908                                          int32_t time, UBool after, UErrorCode& status) {
0909     setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
0910 }
0911 
0912 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
0913                                        int32_t dayOfWeek,
0914                                        int32_t time, UErrorCode& status) {
0915     setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
0916 }
0917 
0918 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
0919                                        int32_t time, UErrorCode& status) {
0920     setEndRule(month, dayOfMonth, time, WALL_TIME, status);
0921 }
0922 
0923 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
0924                                        int32_t time, UBool after, UErrorCode& status) {
0925     setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
0926 }
0927 
0928 inline void
0929 SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
0930                           int32_t& dstOffsetRef, UErrorCode& ec) const {
0931     TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
0932 }
0933 
0934 U_NAMESPACE_END
0935 
0936 #endif /* #if !UCONFIG_NO_FORMATTING */
0937 
0938 #endif /* U_SHOW_CPLUSPLUS_API */
0939 
0940 #endif // _SIMPLETZ