ICU 73.2  73.2
gregocal.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
00005 * All Rights Reserved.
00006 ********************************************************************************
00007 *
00008 * File GREGOCAL.H
00009 *
00010 * Modification History:
00011 *
00012 *   Date        Name        Description
00013 *   04/22/97    aliu        Overhauled header.
00014 *    07/28/98    stephen        Sync with JDK 1.2
00015 *    09/04/98    stephen        Re-sync with JDK 8/31 putback
00016 *    09/14/98    stephen        Changed type of kOneDay, kOneWeek to double.
00017 *                            Fixed bug in roll()
00018 *   10/15/99    aliu        Fixed j31, incorrect WEEK_OF_YEAR computation.
00019 *                           Added documentation of WEEK_OF_YEAR computation.
00020 *   10/15/99    aliu        Fixed j32, cannot set date to Feb 29 2000 AD.
00021 *                           {JDK bug 4210209 4209272}
00022 *   11/07/2003  srl         Update, clean up documentation.
00023 ********************************************************************************
00024 */
00025 
00026 #ifndef GREGOCAL_H
00027 #define GREGOCAL_H
00028 
00029 #include "unicode/utypes.h"
00030 
00031 #if U_SHOW_CPLUSPLUS_API
00032 
00033 #if !UCONFIG_NO_FORMATTING
00034 
00035 #include "unicode/calendar.h"
00036 
00042 U_NAMESPACE_BEGIN
00043 
00153 class U_I18N_API GregorianCalendar: public Calendar {
00154 public:
00155 
00160     enum EEras {
00161         BC,
00162         AD
00163     };
00164 
00173     GregorianCalendar(UErrorCode& success);
00174 
00185     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
00186 
00196     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
00197 
00207     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
00208 
00220     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
00221 
00232     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
00233 
00246     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
00247 
00262     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
00263 
00279     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
00280 
00285     virtual ~GregorianCalendar();
00286 
00292     GregorianCalendar(const GregorianCalendar& source);
00293 
00299     GregorianCalendar& operator=(const GregorianCalendar& right);
00300 
00306     virtual GregorianCalendar* clone() const override;
00307 
00317     void setGregorianChange(UDate date, UErrorCode& success);
00318 
00327     UDate getGregorianChange(void) const;
00328 
00344     UBool isLeapYear(int32_t year) const;
00345 
00353     virtual UBool isEquivalentTo(const Calendar& other) const override;
00354 
00355 #ifndef U_FORCE_HIDE_DEPRECATED_API
00356 
00367     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) override;
00368 #endif  // U_FORCE_HIDE_DEPRECATED_API
00369 
00381     virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) override;
00382 
00383 #ifndef U_HIDE_DEPRECATED_API
00384 
00391     int32_t getActualMinimum(EDateFields field) const;
00392 
00401     int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
00402 #endif  /* U_HIDE_DEPRECATED_API */
00403 
00412     int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override;
00413 
00424     virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override;
00425 
00426 public:
00427 
00438     virtual UClassID getDynamicClassID(void) const override;
00439 
00451     static UClassID U_EXPORT2 getStaticClassID(void);
00452 
00463     virtual const char * getType() const override;
00464 
00465  private:
00466     GregorianCalendar() = delete; // default constructor not implemented
00467 
00468  protected:
00475     virtual int32_t internalGetEra() const;
00476 
00490     virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
00491                                                    UBool useMonth) const override;
00492 
00501     virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) override;
00502 
00510     virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const override;
00511 
00519     virtual int32_t handleGetYearLength(int32_t eyear) const override;
00520 
00527     virtual int32_t monthLength(int32_t month) const;
00528 
00536     virtual int32_t monthLength(int32_t month, int32_t year) const;
00537 
00538 #ifndef U_HIDE_INTERNAL_API
00539 
00545     int32_t yearLength(int32_t year) const;
00546     
00552     int32_t yearLength(void) const;
00553 
00561     void pinDayOfMonth(void);
00562 #endif  /* U_HIDE_INTERNAL_API */
00563 
00571     virtual UDate getEpochDay(UErrorCode& status);
00572 
00594     virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
00595 
00604     virtual int32_t handleGetExtendedYear() override;
00605 
00614     virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy) override;
00615 
00616 
00632     virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
00633 
00634  private:
00642     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
00643                                          UBool& isLeap);
00644     
00649     UBool validateFields(void) const;
00650 
00654     UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
00655 
00665     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
00666 
00674     UDate                fGregorianCutover;
00675 
00679     int32_t             fCutoverJulianDay;
00680 
00686     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
00687 
00692     int32_t fGregorianCutoverYear;// = 1582;
00693 
00701     static double millisToJulianDay(UDate millis);
00702 
00710     static UDate julianDayToMillis(double julian);
00711 
00716     UBool fIsGregorian;
00717 
00723     UBool fInvertGregorian;
00724 
00725 
00726  public: // internal implementation
00727 
00732     virtual UBool haveDefaultCentury() const override;
00733 
00738     virtual UDate defaultCenturyStart() const override;
00739 
00744     virtual int32_t defaultCenturyStartYear() const override;
00745 };
00746 
00747 U_NAMESPACE_END
00748 
00749 #endif /* #if !UCONFIG_NO_FORMATTING */
00750 
00751 #endif /* U_SHOW_CPLUSPLUS_API */
00752 
00753 #endif // _GREGOCAL
00754 //eof
00755