ICU 66.0.1  66.0.1
gregocal.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
5 * All Rights Reserved.
6 ********************************************************************************
7 *
8 * File GREGOCAL.H
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 * 04/22/97 aliu Overhauled header.
14 * 07/28/98 stephen Sync with JDK 1.2
15 * 09/04/98 stephen Re-sync with JDK 8/31 putback
16 * 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
17 * Fixed bug in roll()
18 * 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
19 * Added documentation of WEEK_OF_YEAR computation.
20 * 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
21 * {JDK bug 4210209 4209272}
22 * 11/07/2003 srl Update, clean up documentation.
23 ********************************************************************************
24 */
25 
26 #ifndef GREGOCAL_H
27 #define GREGOCAL_H
28 
29 #include "unicode/utypes.h"
30 
31 #if U_SHOW_CPLUSPLUS_API
32 
33 #if !UCONFIG_NO_FORMATTING
34 
35 #include "unicode/calendar.h"
36 
42 U_NAMESPACE_BEGIN
43 
154 public:
155 
160  enum EEras {
161  BC,
162  AD
163  };
164 
173  GregorianCalendar(UErrorCode& success);
174 
185  GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
186 
196  GregorianCalendar(const TimeZone& zone, UErrorCode& success);
197 
207  GregorianCalendar(const Locale& aLocale, UErrorCode& success);
208 
220  GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
221 
232  GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
233 
246  GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
247 
262  GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
263 
279  GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
280 
285  virtual ~GregorianCalendar();
286 
292  GregorianCalendar(const GregorianCalendar& source);
293 
300 
306  virtual GregorianCalendar* clone() const;
307 
317  void setGregorianChange(UDate date, UErrorCode& success);
318 
327  UDate getGregorianChange(void) const;
328 
344  UBool isLeapYear(int32_t year) const;
345 
353  virtual UBool isEquivalentTo(const Calendar& other) const;
354 
355 #ifndef U_FORCE_HIDE_DEPRECATED_API
356 
367  virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
368 #endif // U_FORCE_HIDE_DEPRECATED_API
369 
381  virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
382 
383 #ifndef U_HIDE_DEPRECATED_API
384 
391  int32_t getActualMinimum(EDateFields field) const;
392 
401  int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
402 #endif /* U_HIDE_DEPRECATED_API */
403 
412  int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
413 
414 #ifndef U_HIDE_DEPRECATED_API
415 
424  int32_t getActualMaximum(EDateFields field) const;
425 #endif /* U_HIDE_DEPRECATED_API */
426 
437  virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
438 
448  virtual UBool inDaylightTime(UErrorCode& status) const;
449 
450 public:
451 
462  virtual UClassID getDynamicClassID(void) const;
463 
475  static UClassID U_EXPORT2 getStaticClassID(void);
476 
487  virtual const char * getType() const;
488 
489  private:
490  GregorianCalendar(); // default constructor not implemented
491 
492  protected:
499  virtual int32_t internalGetEra() const;
500 
514  virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
515  UBool useMonth) const;
516 
525  virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
526 
534  virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
535 
543  virtual int32_t handleGetYearLength(int32_t eyear) const;
544 
551  virtual int32_t monthLength(int32_t month) const;
552 
560  virtual int32_t monthLength(int32_t month, int32_t year) const;
561 
562 #ifndef U_HIDE_INTERNAL_API
563 
569  int32_t yearLength(int32_t year) const;
570 
576  int32_t yearLength(void) const;
577 
585  void pinDayOfMonth(void);
586 #endif /* U_HIDE_INTERNAL_API */
587 
595  virtual UDate getEpochDay(UErrorCode& status);
596 
618  virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
619 
628  virtual int32_t handleGetExtendedYear();
629 
638  virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
639 
640 
656  virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
657 
658  private:
666  static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
667  UBool& isLeap);
668 
673  UBool validateFields(void) const;
674 
678  UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
679 
689  int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
690 
698  UDate fGregorianCutover;
699 
703  int32_t fCutoverJulianDay;
704 
710  UDate fNormalizedGregorianCutover;// = gregorianCutover;
711 
716  int32_t fGregorianCutoverYear;// = 1582;
717 
722  int32_t fGregorianCutoverJulianDay;// = 2299161;
723 
731  static double millisToJulianDay(UDate millis);
732 
740  static UDate julianDayToMillis(double julian);
741 
746  UBool fIsGregorian;
747 
753  UBool fInvertGregorian;
754 
755 
756  public: // internal implementation
757 
762  virtual UBool haveDefaultCentury() const;
763 
768  virtual UDate defaultCenturyStart() const;
769 
774  virtual int32_t defaultCenturyStartYear() const;
775 };
776 
777 U_NAMESPACE_END
778 
779 #endif /* #if !UCONFIG_NO_FORMATTING */
780 
781 #endif /* U_SHOW_CPLUSPLUS_API */
782 
783 #endif // _GREGOCAL
784 //eof
785 
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:199
virtual int32_t defaultCenturyStartYear() const =0
EEras
Useful constants for GregorianCalendar and TimeZone.
Definition: gregocal.h:160
int32_t getActualMaximum(EDateFields field, UErrorCode &status) const
Return the maximum value that this field could have, given the current date.
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status)
Subclasses may override this method to compute several fields specific to each calendar system...
virtual Calendar * clone() const =0
Create and return a polymorphic copy of this calendar.
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:187
double UDate
Date and Time data type.
Definition: utypes.h:203
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const =0
Return the Julian day number of day before the first day of the given month in the given extended yea...
virtual UBool isEquivalentTo(const Calendar &other) const
Returns TRUE if the given Calendar object is equivalent to this one.
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
ELimitType
Limit enums.
Definition: calendar.h:1610
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const
Return the number of days in the given month of the given extended year of this calendar system...
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:301
C++ API: Calendar object.
virtual UBool haveDefaultCentury() const =0
virtual const char * getType() const =0
Returns the calendar type name string for this Calendar object.
void roll(EDateFields field, UBool up, UErrorCode &status)
Time Field Rolling function.
Definition: calendar.h:2515
virtual int32_t handleGetYearLength(int32_t eyear) const
Return the number of days in the given extended year of this calendar system.
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField)
Subclasses may override this.
virtual UBool inDaylightTime(UErrorCode &status) const =0
Queries if the current date for this Calendar is in Daylight Savings Time.
Calendar & operator=(const Calendar &right)
Default assignment operator.
Concrete class which provides the standard calendar used by most of the world.
Definition: gregocal.h:153
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
EDateFields
Field IDs for date and time.
Definition: calendar.h:196
Basic definitions for ICU, for both C and C++ APIs.
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy)
Subclasses must override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended ...
virtual UDate defaultCenturyStart() const =0
int32_t getActualMinimum(EDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
virtual int32_t handleGetExtendedYear()=0
Return the extended year defined by the current fields.
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const =0
Subclass API for defining limits of different types.
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195