Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

gregocal.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) {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 
00133 class U_I18N_API GregorianCalendar: public Calendar {
00134 public:
00135 
00139     enum EEras {
00140         BC,
00141         AD
00142     };
00143 
00152     GregorianCalendar(UErrorCode& success);
00153 
00164     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
00165 
00175     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
00176 
00186     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
00187 
00199     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
00200 
00211     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
00212 
00225     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
00226 
00241     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
00242 
00258     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
00259 
00264     virtual ~GregorianCalendar();
00265 
00270     GregorianCalendar(const GregorianCalendar& source);
00271 
00276     GregorianCalendar& operator=(const GregorianCalendar& right);
00277 
00282     virtual Calendar* clone(void) const;
00283 
00293     void setGregorianChange(UDate date, UErrorCode& success);
00294 
00303     UDate getGregorianChange(void) const;
00304 
00320     UBool isLeapYear(int32_t year) const;
00321 
00332     virtual UBool operator==(const Calendar& that) const;
00333 
00340     virtual UBool equivalentTo(const Calendar& other) const;
00341 
00354     virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
00355 
00367     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
00368 
00374     virtual int32_t getMinimum(EDateFields field) const;
00375 
00381     virtual int32_t getMaximum(EDateFields field) const;
00382 
00388     virtual int32_t getGreatestMinimum(EDateFields field) const;
00389 
00395     virtual int32_t getLeastMaximum(EDateFields field) const;
00396 
00402     int32_t getActualMinimum(EDateFields field) const;
00403 
00411     int32_t getActualMaximum(EDateFields field) const;
00412 
00422     virtual UBool inDaylightTime(UErrorCode& status) const;
00423 
00424 public:
00425 
00436     virtual UClassID getDynamicClassID(void) const { return (UClassID)&fgClassID; }
00437 
00449     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00450 
00451 protected:
00452 
00457     virtual void computeFields(UErrorCode& status);
00458 
00468     virtual void computeTime(UErrorCode& status);
00469 
00470 private:
00471 
00476     int32_t internalGetEra() const;
00477 
00478     // this is 2^52 - 1, the largest allowable mantissa with a 0 exponent in a 64-bit double
00479     static const UDate EARLIEST_SUPPORTED_MILLIS;
00480     static const UDate LATEST_SUPPORTED_MILLIS;
00481 
00482     int32_t monthLength(int32_t month) const;
00483     int32_t monthLength(int32_t month, int32_t year) const;
00484 
00485     int32_t yearLength(int32_t year) const;
00486 
00487     int32_t yearLength(void) const;
00488 
00495     void pinDayOfMonth(void);
00496 
00501     UDate getEpochDay(UErrorCode& status);
00502 
00503     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
00504                                          UBool& isLeap);
00505 
00506     int32_t computeRelativeDOW() const;
00507 
00508     int32_t computeRelativeDOW(double julianDay) const;
00509 
00510     int32_t computeDOYfromWOY(double julianDayOfYear) const;
00511 
00520     double computeJulianDay(UBool isGregorian, int32_t year);
00521 
00531     void timeToFields(UDate theTime, UBool quick, UErrorCode& status);
00532 
00533 
00548     int32_t weekNumber(int32_t date, int32_t day);
00549 
00553     UBool validateFields(void) const;
00554 
00558     UBool boundsCheck(int32_t value, EDateFields field) const;
00559 
00566     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
00567 
00575     // This is measured from the standard epoch, not in Julian Days.
00576     UDate                fGregorianCutover;
00577 
00583     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
00584 
00589     int32_t fGregorianCutoverYear;// = 1582;
00590 
00591     static char fgClassID;
00592 
00600     static double millisToJulianDay(UDate millis);
00601 
00609     static UDate julianDayToMillis(double julian);
00610 
00618     static uint8_t julianDayToDayOfWeek(double julian);
00619 
00630     static double floorDivide(double numerator, double denominator);
00631 
00642     static int32_t floorDivide(int32_t numerator, int32_t denominator);
00643 
00658     static int32_t floorDivide(int32_t numerator, int32_t denominator, int32_t remainder[]);
00659 
00674     static int32_t floorDivide(double numerator, int32_t denominator, int32_t remainder[]);
00675 
00676 
00677     static const UDate       kPapalCutover;             // Cutover decreed by Pope Gregory
00678 
00679     static const int32_t     kJan1_1JulianDay;        // January 1, year 1 (Gregorian)
00680     static const int32_t     kEpochStartAsJulianDay; // January 1, 1970 (Gregorian)
00681     static const int32_t     kEpochYear;
00682 
00683     static const int32_t     kNumDays [];
00684     static const int32_t     kLeapNumDays [];
00685     static const int32_t     kMonthLength [];
00686     static const int32_t     kLeapMonthLength [];
00687 
00688     static const int32_t     kMinValues [];
00689     static const int32_t     kLeastMaxValues [];
00690     static const int32_t     kMaxValues [];
00691 
00692     // Useful millisecond constants
00693     static const int32_t    kOneSecond;
00694     static const int32_t    kOneMinute;
00695     static const int32_t    kOneHour;
00696     static const double        kOneDay;
00697     static const double        kOneWeek;
00698 };
00699 
00700 
00701 inline uint8_t GregorianCalendar::julianDayToDayOfWeek(double julian)
00702 {
00703   // If julian is negative, then julian%7 will be negative, so we adjust
00704   // accordingly.  We add 1 because Julian day 0 is Monday.
00705   int8_t dayOfWeek = (int8_t) uprv_fmod(julian + 1, 7);
00706 
00707   uint8_t result = (uint8_t)(dayOfWeek + ((dayOfWeek < 0) ? (7 + SUNDAY) : SUNDAY));
00708   return result;
00709 }
00710 
00711 #endif // _GREGOCAL
00712 //eof
00713 

Generated at Tue Jun 12 14:03:56 2001 for ICU 1.8.1 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000