ICU 64.2  64.2
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 !UCONFIG_NO_FORMATTING
32 
33 #include "unicode/calendar.h"
34 
41 
152 public:
153 
158  enum EEras {
159  BC,
160  AD
161  };
162 
171  GregorianCalendar(UErrorCode& success);
172 
183  GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
184 
194  GregorianCalendar(const TimeZone& zone, UErrorCode& success);
195 
205  GregorianCalendar(const Locale& aLocale, UErrorCode& success);
206 
218  GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
219 
230  GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
231 
244  GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
245 
260  GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
261 
277  GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
278 
283  virtual ~GregorianCalendar();
284 
290  GregorianCalendar(const GregorianCalendar& source);
291 
298 
304  virtual Calendar* clone(void) const;
305 
315  void setGregorianChange(UDate date, UErrorCode& success);
316 
325  UDate getGregorianChange(void) const;
326 
342  UBool isLeapYear(int32_t year) const;
343 
351  virtual UBool isEquivalentTo(const Calendar& other) const;
352 
364  virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
365 
377  virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
378 
379 #ifndef U_HIDE_DEPRECATED_API
380 
387  int32_t getActualMinimum(EDateFields field) const;
388 
397  int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
398 #endif /* U_HIDE_DEPRECATED_API */
399 
408  int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
409 
410 #ifndef U_HIDE_DEPRECATED_API
411 
420  int32_t getActualMaximum(EDateFields field) const;
421 #endif /* U_HIDE_DEPRECATED_API */
422 
433  virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
434 
444  virtual UBool inDaylightTime(UErrorCode& status) const;
445 
446 public:
447 
458  virtual UClassID getDynamicClassID(void) const;
459 
471  static UClassID U_EXPORT2 getStaticClassID(void);
472 
483  virtual const char * getType() const;
484 
485  private:
486  GregorianCalendar(); // default constructor not implemented
487 
488  protected:
495  virtual int32_t internalGetEra() const;
496 
510  virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
511  UBool useMonth) const;
512 
521  virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
522 
530  virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
531 
539  virtual int32_t handleGetYearLength(int32_t eyear) const;
540 
547  virtual int32_t monthLength(int32_t month) const;
548 
556  virtual int32_t monthLength(int32_t month, int32_t year) const;
557 
558 #ifndef U_HIDE_INTERNAL_API
559 
565  int32_t yearLength(int32_t year) const;
566 
572  int32_t yearLength(void) const;
573 
581  void pinDayOfMonth(void);
582 #endif /* U_HIDE_INTERNAL_API */
583 
591  virtual UDate getEpochDay(UErrorCode& status);
592 
614  virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
615 
624  virtual int32_t handleGetExtendedYear();
625 
634  virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
635 
636 
652  virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
653 
654  private:
662  static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
663  UBool& isLeap);
664 
669  UBool validateFields(void) const;
670 
674  UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
675 
685  int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
686 
694  UDate fGregorianCutover;
695 
699  int32_t fCutoverJulianDay;
700 
706  UDate fNormalizedGregorianCutover;// = gregorianCutover;
707 
712  int32_t fGregorianCutoverYear;// = 1582;
713 
718  int32_t fGregorianCutoverJulianDay;// = 2299161;
719 
727  static double millisToJulianDay(UDate millis);
728 
736  static UDate julianDayToMillis(double julian);
737 
742  UBool fIsGregorian;
743 
749  UBool fInvertGregorian;
750 
751 
752  public: // internal implementation
753 
758  virtual UBool haveDefaultCentury() const;
759 
764  virtual UDate defaultCenturyStart() const;
765 
770  virtual int32_t defaultCenturyStartYear() const;
771 };
772 
774 
775 #endif /* #if !UCONFIG_NO_FORMATTING */
776 
777 #endif // _GREGOCAL
778 //eof
779 
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:158
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...
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:185
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:93
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:131
ELimitType
Limit enums.
Definition: calendar.h:1593
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
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
virtual Calendar * clone(void) const =0
Create and return a polymorphic copy of this calendar.
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:2498
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.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
Calendar & operator=(const Calendar &right)
Default assignment operator.
Concrete class which provides the standard calendar used by most of the world.
Definition: gregocal.h:151
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
EDateFields
Field IDs for date and time.
Definition: calendar.h:194
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:225
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192