00001 /* 00002 ******************************************************************************** 00003 * Copyright (C) 1997-1999, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ******************************************************************************** 00006 * 00007 * File CALENDAR.H 00008 * 00009 * Modification History: 00010 * 00011 * Date Name Description 00012 * 04/22/97 aliu Expanded and corrected comments and other header 00013 * contents. 00014 * 05/01/97 aliu Made equals(), before(), after() arguments const. 00015 * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and 00016 * fAreAllFieldsSet. 00017 * 07/27/98 stephen Sync up with JDK 1.2 00018 * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL 00019 * to EDateFields 00020 ******************************************************************************** 00021 */ 00022 00023 #ifndef CALENDAR_H 00024 #define CALENDAR_H 00025 00026 #include "unicode/locid.h" 00027 #include "unicode/timezone.h" 00028 00029 00030 00141 class U_I18N_API Calendar { 00142 public: 00143 00149 enum EDateFields { 00150 ERA, // Example: 0..1 00151 YEAR, // Example: 1..big number 00152 MONTH, // Example: 0..11 00153 WEEK_OF_YEAR, // Example: 1..53 00154 WEEK_OF_MONTH, // Example: 1..4 00155 DATE, // Example: 1..31 00156 DAY_OF_YEAR, // Example: 1..365 00157 DAY_OF_WEEK, // Example: 1..7 00158 DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1 00159 AM_PM, // Example: 0..1 00160 HOUR, // Example: 0..11 00161 HOUR_OF_DAY, // Example: 0..23 00162 MINUTE, // Example: 0..59 00163 SECOND, // Example: 0..59 00164 MILLISECOND, // Example: 0..999 00165 ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR 00166 DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR 00167 // here will go names for 'Y' and 'e' 00168 YEAR_WOY, // 'Y' Example: 1..big number 00169 DOW_LOCAL, // 'e' Example: 1..7 00170 FIELD_COUNT, 00171 00172 DAY_OF_MONTH = DATE // Synonyms 00173 }; 00174 00180 enum EDaysOfWeek { 00181 SUNDAY = 1, 00182 MONDAY, 00183 TUESDAY, 00184 WEDNESDAY, 00185 THURSDAY, 00186 FRIDAY, 00187 SATURDAY 00188 }; 00189 00193 enum EMonths { 00194 JANUARY, 00195 FEBRUARY, 00196 MARCH, 00197 APRIL, 00198 MAY, 00199 JUNE, 00200 JULY, 00201 AUGUST, 00202 SEPTEMBER, 00203 OCTOBER, 00204 NOVEMBER, 00205 DECEMBER, 00206 UNDECIMBER 00207 }; 00208 00212 enum EAmpm { 00213 AM, 00214 PM 00215 }; 00216 00221 virtual ~Calendar(); 00222 00227 virtual Calendar* clone(void) const = 0; 00228 00239 static Calendar* createInstance(UErrorCode& success); 00240 00253 static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success); 00254 00266 static Calendar* createInstance(const TimeZone& zone, UErrorCode& success); 00267 00278 static Calendar* createInstance(const Locale& aLocale, UErrorCode& success); 00279 00293 static Calendar* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success); 00294 00307 static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success); 00308 00318 static const Locale* getAvailableLocales(int32_t& count); 00319 00327 static UDate getNow(void); 00328 00342 inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); } 00343 00351 inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); } 00352 00364 virtual UBool operator==(const Calendar& that) const; 00365 00374 UBool operator!=(const Calendar& that) const {return !operator==(that);} 00375 00390 UBool equals(const Calendar& when, UErrorCode& status) const; 00391 00405 UBool before(const Calendar& when, UErrorCode& status) const; 00406 00420 UBool after(const Calendar& when, UErrorCode& status) const; 00421 00427 virtual UBool equivalentTo(const Calendar& other) const; 00428 00446 virtual void add(EDateFields field, int32_t amount, UErrorCode& status) = 0; 00447 00471 void roll(EDateFields field, UBool up, UErrorCode& status); 00472 00495 virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) = 0; 00496 00548 virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status); 00549 00558 void adoptTimeZone(TimeZone* value); 00559 00567 void setTimeZone(const TimeZone& zone); 00568 00577 const TimeZone& getTimeZone(void) const; 00578 00587 TimeZone* orphanTimeZone(void); 00588 00597 virtual UBool inDaylightTime(UErrorCode& status) const = 0; 00598 00611 void setLenient(UBool lenient); 00612 00619 UBool isLenient(void) const; 00620 00627 void setFirstDayOfWeek(EDaysOfWeek value); 00628 00635 EDaysOfWeek getFirstDayOfWeek(void) const; 00636 00646 void setMinimalDaysInFirstWeek(uint8_t value); 00647 00657 uint8_t getMinimalDaysInFirstWeek(void) const; 00658 00667 virtual int32_t getMinimum(EDateFields field) const = 0; 00668 00677 virtual int32_t getMaximum(EDateFields field) const = 0; 00678 00687 virtual int32_t getGreatestMinimum(EDateFields field) const = 0; 00688 00697 virtual int32_t getLeastMaximum(EDateFields field) const = 0; 00698 00712 int32_t getActualMinimum(EDateFields field, UErrorCode& status) const; 00713 00729 int32_t getActualMaximum(EDateFields field, UErrorCode& status) const; 00730 00744 int32_t get(EDateFields field, UErrorCode& status) const; 00745 00753 UBool isSet(EDateFields field) const; 00754 00762 void set(EDateFields field, int32_t value); 00763 00774 void set(int32_t year, int32_t month, int32_t date); 00775 00788 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute); 00789 00803 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second); 00804 00811 void clear(void); 00812 00821 void clear(EDateFields field); 00822 00838 virtual UClassID getDynamicClassID(void) const = 0; 00839 00840 protected: 00841 00850 Calendar(UErrorCode& success); 00851 00856 Calendar(const Calendar& source); 00857 00862 Calendar& operator=(const Calendar& right); 00863 00874 Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success); 00875 00885 Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success); 00886 00895 virtual void computeTime(UErrorCode& status) = 0; 00896 00904 virtual void computeFields(UErrorCode& status) = 0; 00905 00911 double getTimeInMillis(UErrorCode& status) const; 00912 00918 void setTimeInMillis( double millis, UErrorCode& status ); 00919 00929 void complete(UErrorCode& status); 00930 00939 int32_t internalGet(EDateFields field) const {return fFields[field];} 00940 00947 void internalSet(EDateFields field, int32_t value); 00948 00949 protected: 00953 UBool fIsTimeSet; 00954 00964 UBool fAreFieldsSet; 00965 00970 UBool fAreAllFieldsSet; 00971 00976 UDate internalGetTime(void) const { return fTime; } 00977 00982 void internalSetTime(UDate time) { fTime = time; } 00983 00987 int32_t fFields[FIELD_COUNT]; 00988 00992 UBool fIsSet[FIELD_COUNT]; 00993 00994 // Special values of stamp[] 00995 enum { 00996 kUnset = 0, 00997 kInternallySet, 00998 kMinimumUserStamp 00999 }; 01000 01006 int32_t fStamp[FIELD_COUNT]; 01007 01008 private: 01009 01010 // The next available value for stampp[] 01011 int32_t fNextStamp;// = MINIMUM_USER_STAMP; 01012 01016 UDate fTime; 01017 01021 UBool fLenient; 01022 01027 TimeZone* fZone; 01028 01037 EDaysOfWeek fFirstDayOfWeek; 01038 uint8_t fMinimalDaysInFirstWeek; 01039 01049 void setWeekCountData(const Locale& desiredLocale, UErrorCode& success); 01050 01056 void updateTime(UErrorCode& status); 01057 01064 static int32_t stringToDayNumber(const UnicodeString& string, UErrorCode& status); 01065 01069 static const char* kDateTimeElements; 01070 }; 01071 01072 // ------------------------------------- 01073 01074 inline Calendar* 01075 Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode) 01076 { 01077 // since the Locale isn't specified, use the default locale 01078 return createInstance(zone, Locale::getDefault(), errorCode); 01079 } 01080 01081 // ------------------------------------- 01082 01083 inline void 01084 Calendar::roll(EDateFields field, UBool up, UErrorCode& status) 01085 { 01086 roll(field, (int32_t)(up ? +1 : -1), status); 01087 } 01088 01089 // ------------------------------------- 01090 01095 inline void 01096 Calendar::internalSet(EDateFields field, int32_t value) 01097 { 01098 fFields[field] = value; 01099 } 01100 01101 #endif // _CALENDAR