- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- Search for |

- File List
- Globals

# simpletz.h

Go to the documentation of this file.

    00001 /*
    00002  ********************************************************************************
    00003  * Copyright (C) 1997-2009, International Business Machines                     *
    00004  * Corporation and others. All Rights Reserved.                                 *
    00005  ********************************************************************************
    00006  *
    00007  * File SIMPLETZ.H
    00008  *
    00009  * Modification History:
    00010  *
    00011  *   Date        Name        Description
    00012  *   04/21/97    aliu        Overhauled header.
    00013  *   08/10/98    stephen     JDK 1.2 sync
    00014  *                           Added setStartRule() / setEndRule() overloads
    00015  *                           Added hasSameRules()
    00016  *   09/02/98    stephen     Added getOffset(monthLen)
    00017  *                           Changed getOffset() to take UErrorCode
    00018  *   07/09/99    stephen     Removed millisPerHour (unused, for HP compiler)
    00019  *   12/02/99    aliu        Added TimeMode and constructor and setStart/EndRule
    00020  *                           methods that take TimeMode. Added to docs.
    00021  ********************************************************************************
    00022  */
    00023
    00024 #ifndef SIMPLETZ_H
    00025 #define SIMPLETZ_H
    00026
    00027 #include "unicode/utypes.h"
    00028
    00034 #if !UCONFIG_NO_FORMATTING
    00035
    00036 #include "unicode/basictz.h"
    00037
    00038 U_NAMESPACE_BEGIN
    00039
    00040 // forward declaration
    00041 class InitialTimeZoneRule;
    00042 class TimeZoneTransition;
    00043 class AnnualTimeZoneRule;
    00044
    00061 class U_I18N_API SimpleTimeZone: public BasicTimeZone {
    00062 public:
    00063
    00075     enum TimeMode {
    00076         WALL_TIME = 0,
    00077         STANDARD_TIME,
    00078         UTC_TIME
    00079     };
    00080
    00086     SimpleTimeZone(const SimpleTimeZone& source);
    00087
    00093     SimpleTimeZone& operator=(const SimpleTimeZone& right);
    00094
    00099     virtual ~SimpleTimeZone();
    00100
    00110     virtual UBool operator==(const TimeZone& that) const;
    00111
    00123     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID);
    00124
    00160     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
    00161         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
    00162         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
    00163         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
    00164         int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
    00165         UErrorCode& status);
    00203     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
    00204         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
    00205         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
    00206         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
    00207         int8_t savingsEndDayOfWeek, int32_t savingsEndTime,
    00208         int32_t savingsDST, UErrorCode& status);
    00209
    00251     SimpleTimeZone(int32_t rawOffsetGMT, const UnicodeString& ID,
    00252         int8_t savingsStartMonth, int8_t savingsStartDayOfWeekInMonth,
    00253         int8_t savingsStartDayOfWeek, int32_t savingsStartTime,
    00254         TimeMode savingsStartTimeMode,
    00255         int8_t savingsEndMonth, int8_t savingsEndDayOfWeekInMonth,
    00256         int8_t savingsEndDayOfWeek, int32_t savingsEndTime, TimeMode savingsEndTimeMode,
    00257         int32_t savingsDST, UErrorCode& status);
    00258
    00267     void setStartYear(int32_t year);
    00268
    00311     void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
    00312                       int32_t time, UErrorCode& status);
    00357     void setStartRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
    00358                       int32_t time, TimeMode mode, UErrorCode& status);
    00359
    00371     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
    00372                       UErrorCode& status);
    00386     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t time,
    00387                       TimeMode mode, UErrorCode& status);
    00388
    00405     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
    00406                       int32_t time, UBool after, UErrorCode& status);
    00425     void setStartRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
    00426                       int32_t time, TimeMode mode, UBool after, UErrorCode& status);
    00427
    00450     void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
    00451                     int32_t time, UErrorCode& status);
    00452
    00477     void setEndRule(int32_t month, int32_t dayOfWeekInMonth, int32_t dayOfWeek,
    00478                     int32_t time, TimeMode mode, UErrorCode& status);
    00479
    00491     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time, UErrorCode& status);
    00492
    00506     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t time,
    00507                     TimeMode mode, UErrorCode& status);
    00508
    00525     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
    00526                     int32_t time, UBool after, UErrorCode& status);
    00527
    00546     void setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
    00547                     int32_t time, TimeMode mode, UBool after, UErrorCode& status);
    00548
    00569     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
    00570                               uint8_t dayOfWeek, int32_t millis, UErrorCode& status) const;
    00571
    00587     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
    00588                            uint8_t dayOfWeek, int32_t milliseconds,
    00589                            int32_t monthLength, UErrorCode& status) const;
    00606     virtual int32_t getOffset(uint8_t era, int32_t year, int32_t month, int32_t day,
    00607                               uint8_t dayOfWeek, int32_t milliseconds,
    00608                               int32_t monthLength, int32_t prevMonthLength,
    00609                               UErrorCode& status) const;
    00610
    00616     virtual void getOffset(UDate date, UBool local, int32_t& rawOffset,
    00617                            int32_t& dstOffset, UErrorCode& ec) const;
    00618
    00623     virtual void getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
    00624         int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) /*const*/;
    00625
    00633     virtual int32_t getRawOffset(void) const;
    00634
    00642     virtual void setRawOffset(int32_t offsetMillis);
    00643
    00652     void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
    00653
    00661     virtual int32_t getDSTSavings(void) const;
    00662
    00669     virtual UBool useDaylightTime(void) const;
    00670
    00685     virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
    00686
    00693     UBool hasSameRules(const TimeZone& other) const;
    00694
    00702     virtual TimeZone* clone(void) const;
    00703
    00712     virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
    00713
    00722     virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
    00723
    00732     virtual int32_t countTransitionRules(UErrorCode& status) /*const*/;
    00733
    00750     virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
    00751         const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) /*const*/;
    00752
    00753
    00754 public:
    00755
    00766     virtual UClassID getDynamicClassID(void) const;
    00767
    00779     static UClassID U_EXPORT2 getStaticClassID(void);
    00780
    00781 private:
    00785     enum EMode
    00786     {
    00787         DOM_MODE = 1,
    00788         DOW_IN_MONTH_MODE,
    00789         DOW_GE_DOM_MODE,
    00790         DOW_LE_DOM_MODE
    00791     };
    00792
    00793     SimpleTimeZone(); // default constructor not implemented
    00794
    00814     void construct(int32_t rawOffsetGMT,
    00815                    int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
    00816                    int32_t startTime, TimeMode startTimeMode,
    00817                    int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
    00818                    int32_t endTime, TimeMode endTimeMode,
    00819                    int32_t dstSavings, UErrorCode& status);
    00820
    00830     static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
    00831                                  int8_t dayOfMonth,
    00832                                  int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
    00833                                  EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
    00834                                  int8_t ruleDay, int32_t ruleMillis);
    00835
    00851     void decodeRules(UErrorCode& status);
    00852     void decodeStartRule(UErrorCode& status);
    00853     void decodeEndRule(UErrorCode& status);
    00854
    00855     int8_t startMonth, startDay, startDayOfWeek;   // the month, day, DOW, and time DST starts
    00856     int32_t startTime;
    00857     TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
    00858     int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
    00859     int32_t endTime;
    00860     int32_t startYear;  // the year these DST rules took effect
    00861     int32_t rawOffset;  // the TimeZone's raw GMT offset
    00862     UBool useDaylight; // flag indicating whether this TimeZone uses DST
    00863     static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
    00864     EMode startMode, endMode;   // flags indicating what kind of rules the DST rules are
    00865
    00870     int32_t dstSavings;
    00871
    00872     /* Private for BasicTimeZone implementation */
    00873     void initTransitionRules(UErrorCode& status);
    00874     void clearTransitionRules(void);
    00875     void deleteTransitionRules(void);
    00876     UBool   transitionRulesInitialized;
    00877     InitialTimeZoneRule*    initialRule;
    00878     TimeZoneTransition*     firstTransition;
    00879     AnnualTimeZoneRule*     stdRule;
    00880     AnnualTimeZoneRule*     dstRule;
    00881 };
    00882
    00883 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
    00884                                          int32_t dayOfWeek,
    00885                                          int32_t time, UErrorCode& status) {
    00886     setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
    00887 }
    00888
    00889 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
    00890                                          int32_t time,
    00891                                          UErrorCode& status) {
    00892     setStartRule(month, dayOfMonth, time, WALL_TIME, status);
    00893 }
    00894
    00895 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
    00896                                          int32_t dayOfWeek,
    00897                                          int32_t time, UBool after, UErrorCode& status) {
    00898     setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
    00899 }
    00900
    00901 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
    00902                                        int32_t dayOfWeek,
    00903                                        int32_t time, UErrorCode& status) {
    00904     setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
    00905 }
    00906
    00907 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
    00908                                        int32_t time, UErrorCode& status) {
    00909     setEndRule(month, dayOfMonth, time, WALL_TIME, status);
    00910 }
    00911
    00912 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
    00913                                        int32_t time, UBool after, UErrorCode& status) {
    00914     setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
    00915 }
    00916
    00917 inline void
    00918 SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
    00919                           int32_t& dstOffsetRef, UErrorCode& ec) const {
    00920     TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
    00921 }
    00922
    00923 U_NAMESPACE_END
    00924
    00925 #endif /* #if !UCONFIG_NO_FORMATTING */
    00926
    00927 #endif // _SIMPLETZ