00001 /* 00002 * Copyright © {1997-1999}, International Business Machines Corporation and others. All Rights Reserved. 00003 ******************************************************************************** 00004 * 00005 * File GREGOCAL.H 00006 * 00007 * Modification History: 00008 * 00009 * Date Name Description 00010 * 04/22/97 aliu Overhauled header. 00011 * 07/28/98 stephen Sync with JDK 1.2 00012 * 09/04/98 stephen Re-sync with JDK 8/31 putback 00013 * 09/14/98 stephen Changed type of kOneDay, kOneWeek to double. 00014 * Fixed bug in roll() 00015 * 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation. 00016 * Added documentation of WEEK_OF_YEAR computation. 00017 * 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD. 00018 * {JDK bug 4210209 4209272} 00019 ******************************************************************************** 00020 */ 00021 00022 #ifndef GREGOCAL_H 00023 #define GREGOCAL_H 00024 00025 00026 #include "unicode/calendar.h" 00027 00132 class U_I18N_API GregorianCalendar: public Calendar { 00133 public: 00134 00138 enum EEras { 00139 BC, 00140 AD 00141 }; 00142 00151 GregorianCalendar(UErrorCode& success); 00152 00163 GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success); 00164 00174 GregorianCalendar(const TimeZone& zone, UErrorCode& success); 00175 00185 GregorianCalendar(const Locale& aLocale, UErrorCode& success); 00186 00198 GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success); 00199 00210 GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success); 00211 00224 GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success); 00225 00240 GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success); 00241 00257 GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success); 00258 00263 virtual ~GregorianCalendar(); 00264 00269 GregorianCalendar(const GregorianCalendar& source); 00270 00275 GregorianCalendar& operator=(const GregorianCalendar& right); 00276 00281 virtual Calendar* clone(void) const; 00282 00292 void setGregorianChange(UDate date, UErrorCode& success); 00293 00302 UDate getGregorianChange(void) const; 00303 00319 UBool isLeapYear(int32_t year) const; 00320 00331 virtual UBool operator==(const Calendar& that) const; 00332 00339 virtual UBool equivalentTo(const Calendar& other) const; 00340 00353 virtual void add(EDateFields field, int32_t amount, UErrorCode& status); 00354 00366 virtual void roll(EDateFields field, int32_t amount, UErrorCode& status); 00367 00373 virtual int32_t getMinimum(EDateFields field) const; 00374 00380 virtual int32_t getMaximum(EDateFields field) const; 00381 00387 virtual int32_t getGreatestMinimum(EDateFields field) const; 00388 00394 virtual int32_t getLeastMaximum(EDateFields field) const; 00395 00401 int32_t getActualMinimum(EDateFields field) const; 00402 00410 int32_t getActualMaximum(EDateFields field) const; 00411 00421 virtual UBool inDaylightTime(UErrorCode& status) const; 00422 00423 public: 00424 00435 virtual UClassID getDynamicClassID(void) const { return (UClassID)&fgClassID; } 00436 00448 static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; } 00449 00450 protected: 00451 00456 virtual void computeFields(UErrorCode& status); 00457 00467 virtual void computeTime(UErrorCode& status); 00468 00469 private: 00470 00475 int32_t internalGetEra() const; 00476 00477 // this is 2^52 - 1, the largest allowable mantissa with a 0 exponent in a 64-bit double 00478 static const UDate EARLIEST_SUPPORTED_MILLIS; 00479 static const UDate LATEST_SUPPORTED_MILLIS; 00480 00481 int32_t monthLength(int32_t month) const; 00482 int32_t monthLength(int32_t month, int32_t year) const; 00483 00484 int32_t yearLength(int32_t year) const; 00485 00486 int32_t yearLength(void) const; 00487 00494 void pinDayOfMonth(void); 00495 00500 UDate getEpochDay(UErrorCode& status); 00501 00502 static double computeJulianDayOfYear(UBool isGregorian, int32_t year, 00503 UBool& isLeap); 00504 00505 int32_t computeRelativeDOW() const; 00506 00507 int32_t computeRelativeDOW(double julianDay) const; 00508 00509 int32_t computeDOYfromWOY(double julianDayOfYear) const; 00510 00519 double computeJulianDay(UBool isGregorian, int32_t year); 00520 00530 void timeToFields(UDate theTime, UBool quick, UErrorCode& status); 00531 00532 00547 int32_t weekNumber(int32_t date, int32_t day); 00548 00552 UBool validateFields(void) const; 00553 00557 UBool boundsCheck(int32_t value, EDateFields field) const; 00558 00565 int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b); 00566 00574 // This is measured from the standard epoch, not in Julian Days. 00575 UDate fGregorianCutover; 00576 00582 UDate fNormalizedGregorianCutover;// = gregorianCutover; 00583 00588 int32_t fGregorianCutoverYear;// = 1582; 00589 00590 static char fgClassID; 00591 00599 static double millisToJulianDay(UDate millis); 00600 00608 static UDate julianDayToMillis(double julian); 00609 00617 static uint8_t julianDayToDayOfWeek(double julian); 00618 00629 static double floorDivide(double numerator, double denominator); 00630 00641 static int32_t floorDivide(int32_t numerator, int32_t denominator); 00642 00657 static int32_t floorDivide(int32_t numerator, int32_t denominator, int32_t remainder[]); 00658 00673 static int32_t floorDivide(double numerator, int32_t denominator, int32_t remainder[]); 00674 00675 00676 static const UDate kPapalCutover; // Cutover decreed by Pope Gregory 00677 00678 static const int32_t kJan1_1JulianDay; // January 1, year 1 (Gregorian) 00679 static const int32_t kEpochStartAsJulianDay; // January 1, 1970 (Gregorian) 00680 static const int32_t kEpochYear; 00681 00682 static const int32_t kNumDays []; 00683 static const int32_t kLeapNumDays []; 00684 static const int32_t kMonthLength []; 00685 static const int32_t kLeapMonthLength []; 00686 00687 static const int32_t kMinValues []; 00688 static const int32_t kLeastMaxValues []; 00689 static const int32_t kMaxValues []; 00690 00691 // Useful millisecond constants 00692 static const int32_t kOneSecond; 00693 static const int32_t kOneMinute; 00694 static const int32_t kOneHour; 00695 static const double kOneDay; 00696 static const double kOneWeek; 00697 }; 00698 00699 00700 inline uint8_t GregorianCalendar::julianDayToDayOfWeek(double julian) 00701 { 00702 // If julian is negative, then julian%7 will be negative, so we adjust 00703 // accordingly. We add 1 because Julian day 0 is Monday. 00704 int8_t dayOfWeek = (int8_t) uprv_fmod(julian + 1, 7); 00705 00706 uint8_t result = (uint8_t)(dayOfWeek + ((dayOfWeek < 0) ? (7 + SUNDAY) : SUNDAY)); 00707 return result; 00708 } 00709 00710 #endif // _GREGOCAL 00711 //eof 00712