simpletz.h

Go to the documentation of this file.
00001 /*
00002  ********************************************************************************
00003  * Copyright (C) 1997-2007, 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 
00626     virtual int32_t getRawOffset(void) const;
00627 
00635     virtual void setRawOffset(int32_t offsetMillis);
00636 
00645     void setDSTSavings(int32_t millisSavedDuringDST, UErrorCode& status);
00646 
00654     virtual int32_t getDSTSavings(void) const;
00655 
00662     virtual UBool useDaylightTime(void) const;
00663 
00678     virtual UBool inDaylightTime(UDate date, UErrorCode& status) const;
00679 
00686     UBool hasSameRules(const TimeZone& other) const;
00687 
00695     virtual TimeZone* clone(void) const;
00696 
00705     virtual UBool getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
00706 
00715     virtual UBool getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/;
00716 
00725     virtual int32_t countTransitionRules(UErrorCode& status) /*const*/;
00726 
00743     virtual void getTimeZoneRules(const InitialTimeZoneRule*& initial,
00744         const TimeZoneRule* trsrules[], int32_t& trscount, UErrorCode& status) /*const*/;
00745 
00746 
00747 public:
00748 
00759     virtual UClassID getDynamicClassID(void) const;
00760 
00772     static UClassID U_EXPORT2 getStaticClassID(void);
00773 
00774 private:
00778     enum EMode
00779     {
00780         DOM_MODE = 1,
00781         DOW_IN_MONTH_MODE,
00782         DOW_GE_DOM_MODE,
00783         DOW_LE_DOM_MODE
00784     };
00785 
00786     SimpleTimeZone(); // default constructor not implemented
00787 
00807     void construct(int32_t rawOffsetGMT,
00808                    int8_t startMonth, int8_t startDay, int8_t startDayOfWeek,
00809                    int32_t startTime, TimeMode startTimeMode,
00810                    int8_t endMonth, int8_t endDay, int8_t endDayOfWeek,
00811                    int32_t endTime, TimeMode endTimeMode,
00812                    int32_t dstSavings, UErrorCode& status);
00813 
00823     static int32_t compareToRule(int8_t month, int8_t monthLen, int8_t prevMonthLen,
00824                                  int8_t dayOfMonth,
00825                                  int8_t dayOfWeek, int32_t millis, int32_t millisDelta,
00826                                  EMode ruleMode, int8_t ruleMonth, int8_t ruleDayOfWeek,
00827                                  int8_t ruleDay, int32_t ruleMillis);
00828 
00844     void decodeRules(UErrorCode& status);
00845     void decodeStartRule(UErrorCode& status);
00846     void decodeEndRule(UErrorCode& status);
00847 
00848     int8_t startMonth, startDay, startDayOfWeek;   // the month, day, DOW, and time DST starts
00849     int32_t startTime;
00850     TimeMode startTimeMode, endTimeMode; // Mode for startTime, endTime; see TimeMode
00851     int8_t endMonth, endDay, endDayOfWeek; // the month, day, DOW, and time DST ends
00852     int32_t endTime;
00853     int32_t startYear;  // the year these DST rules took effect
00854     int32_t rawOffset;  // the TimeZone's raw GMT offset
00855     UBool useDaylight; // flag indicating whether this TimeZone uses DST
00856     static const int8_t STATICMONTHLENGTH[12]; // lengths of the months
00857     EMode startMode, endMode;   // flags indicating what kind of rules the DST rules are
00858 
00863     int32_t dstSavings;
00864 
00865     /* Private for BasicTimeZone implementation */
00866     void initTransitionRules(UErrorCode& status);
00867     void clearTransitionRules(void);
00868     void deleteTransitionRules(void);
00869     UBool   transitionRulesInitialized;
00870     InitialTimeZoneRule*    initialRule;
00871     TimeZoneTransition*     firstTransition;
00872     AnnualTimeZoneRule*     stdRule;
00873     AnnualTimeZoneRule*     dstRule;
00874 };
00875 
00876 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfWeekInMonth,
00877                                          int32_t dayOfWeek,
00878                                          int32_t time, UErrorCode& status) {
00879     setStartRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
00880 }
00881 
00882 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
00883                                          int32_t time,
00884                                          UErrorCode& status) {
00885     setStartRule(month, dayOfMonth, time, WALL_TIME, status);
00886 }
00887 
00888 inline void SimpleTimeZone::setStartRule(int32_t month, int32_t dayOfMonth,
00889                                          int32_t dayOfWeek,
00890                                          int32_t time, UBool after, UErrorCode& status) {
00891     setStartRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
00892 }
00893 
00894 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfWeekInMonth,
00895                                        int32_t dayOfWeek,
00896                                        int32_t time, UErrorCode& status) {
00897     setEndRule(month, dayOfWeekInMonth, dayOfWeek, time, WALL_TIME, status);
00898 }
00899 
00900 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth,
00901                                        int32_t time, UErrorCode& status) {
00902     setEndRule(month, dayOfMonth, time, WALL_TIME, status);
00903 }
00904 
00905 inline void SimpleTimeZone::setEndRule(int32_t month, int32_t dayOfMonth, int32_t dayOfWeek,
00906                                        int32_t time, UBool after, UErrorCode& status) {
00907     setEndRule(month, dayOfMonth, dayOfWeek, time, WALL_TIME, after, status);
00908 }
00909 
00910 inline void
00911 SimpleTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffsetRef,
00912                           int32_t& dstOffsetRef, UErrorCode& ec) const {
00913     TimeZone::getOffset(date, local, rawOffsetRef, dstOffsetRef, ec);
00914 }
00915 
00916 U_NAMESPACE_END
00917 
00918 #endif /* #if !UCONFIG_NO_FORMATTING */
00919 
00920 #endif // _SIMPLETZ

Generated on Mon Sep 3 04:45:38 2007 for ICU 3.8 by  doxygen 1.5.2