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

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 #include "unicode/utypes.h"
00026 
00027 #if !UCONFIG_NO_FORMATTING
00028 
00029 #include "unicode/calendar.h"
00030 
00031 U_NAMESPACE_BEGIN
00032 
00139 class U_I18N_API GregorianCalendar: public Calendar {
00140 public:
00141 
00146     enum EEras {
00147         BC,
00148         AD
00149     };
00150 
00159     GregorianCalendar(UErrorCode& success);
00160 
00171     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
00172 
00182     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
00183 
00193     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
00194 
00206     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
00207 
00218     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
00219 
00232     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
00233 
00248     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
00249 
00265     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
00266 
00271     virtual ~GregorianCalendar();
00272 
00278     GregorianCalendar(const GregorianCalendar& source);
00279 
00285     GregorianCalendar& operator=(const GregorianCalendar& right);
00286 
00292     virtual Calendar* clone(void) const;
00293 
00303     void setGregorianChange(UDate date, UErrorCode& success);
00304 
00313     UDate getGregorianChange(void) const;
00314 
00330     UBool isLeapYear(int32_t year) const;
00331 
00339     virtual UBool isEquivalentTo(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 
00375     virtual int32_t getMinimum(EDateFields field) const;
00376 
00384     virtual int32_t getMaximum(EDateFields field) const;
00385 
00394     virtual int32_t getGreatestMinimum(EDateFields field) const;
00395 
00404     virtual int32_t getLeastMaximum(EDateFields field) const;
00405 
00413     int32_t getActualMinimum(EDateFields field) const;
00414 
00424     int32_t getActualMaximum(EDateFields field) const;
00425 
00435     virtual UBool inDaylightTime(UErrorCode& status) const;
00436 
00437 public:
00438 
00449     virtual UClassID getDynamicClassID(void) const { return (UClassID)&fgClassID; }
00450 
00462     static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
00463 
00464 protected:
00465 
00471     virtual void computeFields(UErrorCode& status);
00472 
00482     virtual void computeTime(UErrorCode& status);
00483 
00484 private:
00485 
00491     int32_t internalGetEra() const;
00492 
00498     int32_t monthLength(int32_t month) const;
00499 
00506     int32_t monthLength(int32_t month, int32_t year) const;
00507     
00513     int32_t yearLength(int32_t year) const;
00514     
00519     int32_t yearLength(void) const;
00520 
00527     void pinDayOfMonth(void);
00528 
00535     UDate getEpochDay(UErrorCode& status);
00536 
00544     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
00545                                          UBool& isLeap);
00546     
00553     int32_t computeRelativeDOW() const;
00554     
00561     int32_t computeRelativeDOW(double julianDay) const;
00562 
00571     int32_t computeDOYfromWOY(double julianDayOfYear) const;
00572 
00581     double computeJulianDay(UBool isGregorian, int32_t year);
00582 
00593     void timeToFields(UDate theTime, UBool quick, UErrorCode& status);
00594 
00595 
00610     int32_t weekNumber(int32_t date, int32_t day);
00611 
00616     UBool validateFields(void) const;
00617 
00621     UBool boundsCheck(int32_t value, EDateFields field) const;
00622 
00632     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
00633 
00641     // This is measured from the standard epoch, not in Julian Days.
00642     UDate                fGregorianCutover;
00643 
00649     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
00650 
00655     int32_t fGregorianCutoverYear;// = 1582;
00656 
00657     static const char fgClassID;
00658 
00666     static double millisToJulianDay(UDate millis);
00667 
00675     static UDate julianDayToMillis(double julian);
00676 
00685     static uint8_t julianDayToDayOfWeek(double julian);
00686 
00697     static double floorDivide(double numerator, double denominator);
00698 
00709     static int32_t floorDivide(int32_t numerator, int32_t denominator);
00710 
00725     static int32_t floorDivide(int32_t numerator, int32_t denominator, int32_t remainder[]);
00726 
00741     static int32_t floorDivide(double numerator, int32_t denominator, int32_t remainder[]);
00742 
00743 };
00744 
00745 
00746 inline uint8_t GregorianCalendar::julianDayToDayOfWeek(double julian)
00747 {
00748   // If julian is negative, then julian%7 will be negative, so we adjust
00749   // accordingly.  We add 1 because Julian day 0 is Monday.
00750   int8_t dayOfWeek = (int8_t) uprv_fmod(julian + 1, 7);
00751 
00752   uint8_t result = (uint8_t)(dayOfWeek + ((dayOfWeek < 0) ? (7 + SUNDAY) : SUNDAY));
00753   return result;
00754 }
00755 
00756 U_NAMESPACE_END
00757 
00758 #endif /* #if !UCONFIG_NO_FORMATTING */
00759 
00760 #endif // _GREGOCAL
00761 //eof
00762 

Generated on Wed Dec 18 16:49:35 2002 for ICU 2.4 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001