Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gregocal.h

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 
00028 U_NAMESPACE_BEGIN
00029 
00136 class U_I18N_API GregorianCalendar: public Calendar {
00137 public:
00138 
00143     enum EEras {
00144         BC,
00145         AD
00146     };
00147 
00156     GregorianCalendar(UErrorCode& success);
00157 
00168     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
00169 
00179     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
00180 
00190     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
00191 
00203     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
00204 
00215     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
00216 
00229     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
00230 
00245     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
00246 
00262     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
00263 
00268     virtual ~GregorianCalendar();
00269 
00274     GregorianCalendar(const GregorianCalendar& source);
00275 
00280     GregorianCalendar& operator=(const GregorianCalendar& right);
00281 
00286     virtual Calendar* clone(void) const;
00287 
00297     void setGregorianChange(UDate date, UErrorCode& success);
00298 
00307     UDate getGregorianChange(void) const;
00308 
00324     UBool isLeapYear(int32_t year) const;
00325 
00336     virtual UBool operator==(const Calendar& that) const;
00337 
00344     virtual UBool equivalentTo(const Calendar& other) const;
00345 
00358     virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
00359 
00371     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
00372 
00378     virtual int32_t getMinimum(EDateFields field) const;
00379 
00385     virtual int32_t getMaximum(EDateFields field) const;
00386 
00392     virtual int32_t getGreatestMinimum(EDateFields field) const;
00393 
00399     virtual int32_t getLeastMaximum(EDateFields field) const;
00400 
00406     int32_t getActualMinimum(EDateFields field) const;
00407 
00415     int32_t getActualMaximum(EDateFields field) const;
00416 
00426     virtual UBool inDaylightTime(UErrorCode& status) const;
00427 
00428 public:
00429 
00440     virtual UClassID getDynamicClassID(void) const { return (UClassID)&fgClassID; }
00441 
00453     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00454 
00455 protected:
00456 
00461     virtual void computeFields(UErrorCode& status);
00462 
00472     virtual void computeTime(UErrorCode& status);
00473 
00474 private:
00475 
00480     int32_t internalGetEra() const;
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 const 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 
00678 
00679 inline uint8_t GregorianCalendar::julianDayToDayOfWeek(double julian)
00680 {
00681   // If julian is negative, then julian%7 will be negative, so we adjust
00682   // accordingly.  We add 1 because Julian day 0 is Monday.
00683   int8_t dayOfWeek = (int8_t) uprv_fmod(julian + 1, 7);
00684 
00685   uint8_t result = (uint8_t)(dayOfWeek + ((dayOfWeek < 0) ? (7 + SUNDAY) : SUNDAY));
00686   return result;
00687 }
00688 
00689 U_NAMESPACE_END
00690 
00691 #endif // _GREGOCAL
00692 //eof
00693 

Generated on Mon Mar 4 22:08:38 2002 for ICU 2.0 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002