gregocal.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
* Copyright (C) 1997-2013, International Business Machines Corporation and others.
* All Rights Reserved.
********************************************************************************
*
* File GREGOCAL.H
*
* Modification History:
*
* Date Name Description
* 04/22/97 aliu Overhauled header.
* 07/28/98 stephen Sync with JDK 1.2
* 09/04/98 stephen Re-sync with JDK 8/31 putback
* 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
* Fixed bug in roll()
* 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
* Added documentation of WEEK_OF_YEAR computation.
* 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
* {JDK bug 4210209 4209272}
* 11/07/2003 srl Update, clean up documentation.
********************************************************************************
*/
#ifndef GREGOCAL_H
#define GREGOCAL_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#if !UCONFIG_NO_FORMATTING
#include "unicode/calendar.h"
U_NAMESPACE_BEGIN
class U_I18N_API GregorianCalendar: public Calendar {
public:
enum EEras {
BC,
AD
};
GregorianCalendar(UErrorCode& success);
GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
GregorianCalendar(const TimeZone& zone, UErrorCode& success);
GregorianCalendar(const Locale& aLocale, UErrorCode& success);
GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
virtual ~GregorianCalendar();
GregorianCalendar(const GregorianCalendar& source);
GregorianCalendar& operator=(const GregorianCalendar& right);
virtual GregorianCalendar* clone() const override;
void setGregorianChange(UDate date, UErrorCode& success);
UDate getGregorianChange() const;
UBool isLeapYear(int32_t year) const;
virtual UBool isEquivalentTo(const Calendar& other) const override;
#ifndef U_FORCE_HIDE_DEPRECATED_API
virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) override;
#endif // U_FORCE_HIDE_DEPRECATED_API
virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) override;
#ifndef U_HIDE_DEPRECATED_API
int32_t getActualMinimum(EDateFields field) const;
int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
#endif /* U_HIDE_DEPRECATED_API */
int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override;
virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override;
public:
virtual UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
virtual const char * getType() const override;
private:
GregorianCalendar() = delete; // default constructor not implemented
protected:
virtual int32_t internalGetEra() const;
virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month,
UBool useMonth, UErrorCode& status) const override;
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode& status) override;
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& status) const override;
virtual int32_t handleGetYearLength(int32_t eyear) const override;
virtual int32_t monthLength(int32_t month, UErrorCode& status) const;
virtual int32_t monthLength(int32_t month, int32_t year) const;
#ifndef U_HIDE_INTERNAL_API
int32_t yearLength() const;
#endif /* U_HIDE_INTERNAL_API */
virtual UDate getEpochDay(UErrorCode& status);
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
virtual int32_t handleGetExtendedYear(UErrorCode& status) override;
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode& status) override;
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
#ifndef U_HIDE_INTERNAL_API
virtual bool isEra0CountingBackward() const override { return true; }
#endif // U_HIDE_INTERNAL_API
private:
static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
UBool& isLeap);
UBool validateFields() const;
UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
UDate fGregorianCutover;
int32_t fCutoverJulianDay;
UDate fNormalizedGregorianCutover;// = gregorianCutover;
int32_t fGregorianCutoverYear;// = 1582;
static double millisToJulianDay(UDate millis);
static UDate julianDayToMillis(double julian);
UBool fIsGregorian;
UBool fInvertGregorian;
public: // internal implementation
DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* U_SHOW_CPLUSPLUS_API */
#endif // _GREGOCAL
//eof
calendar.h
C++ API: Calendar object.
DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY
#define DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY
Macro for the class to declare it override haveDefaultCentury, defaultCenturyStart,...
Definition: calendar.h:2575
icu::Calendar
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:189
icu::Calendar::EDateFields
EDateFields
Field IDs for date and time.
Definition: calendar.h:198
icu::Calendar::ELimitType
ELimitType
Limit enums.
Definition: calendar.h:1621
icu::GregorianCalendar
Concrete class which provides the standard calendar used by most of the world.
Definition: gregocal.h:153
icu::GregorianCalendar::getDynamicClassID
virtual UClassID getDynamicClassID() const override
Override Calendar Returns a unique class ID POLYMORPHICALLY.
icu::GregorianCalendar::getActualMinimum
int32_t getActualMinimum(EDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
icu::GregorianCalendar::handleComputeJulianDay
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode &status) override
Subclasses may override this.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(UErrorCode &success)
Constructs a default GregorianCalendar using the current time in the default time zone with the defau...
icu::GregorianCalendar::handleGetLimit
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override
Subclass API for defining limits of different types.
icu::GregorianCalendar::handleComputeFields
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override
Subclasses may override this method to compute several fields specific to each calendar system.
icu::GregorianCalendar::EEras
EEras
Useful constants for GregorianCalendar and TimeZone.
Definition: gregocal.h:160
icu::GregorianCalendar::monthLength
virtual int32_t monthLength(int32_t month, UErrorCode &status) const
return the length of the given month.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(TimeZone *zoneToAdopt, UErrorCode &success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default loca...
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(const Locale &aLocale, UErrorCode &success)
Constructs a GregorianCalendar based on the current time in the default time zone with the given loca...
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale...
icu::GregorianCalendar::monthLength
virtual int32_t monthLength(int32_t month, int32_t year) const
return the length of the month according to the given year.
icu::GregorianCalendar::getType
virtual const char * getType() const override
Returns the calendar type name string for this Calendar object.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale...
icu::GregorianCalendar::getGregorianChange
UDate getGregorianChange() const
Gets the Gregorian Calendar change date.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode &success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the...
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(const TimeZone &zone, UErrorCode &success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default loca...
icu::GregorianCalendar::isEra0CountingBackward
virtual bool isEra0CountingBackward() const override
The year in this calendar is counting from 1 backward if the era is 0.
Definition: gregocal.h:628
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(const GregorianCalendar &source)
Copy constructor.
icu::GregorianCalendar::handleGetExtendedYearFromWeekFields
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode &status) override
Subclasses may override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended y...
icu::GregorianCalendar::internalGetEra
virtual int32_t internalGetEra() const
Return the ERA.
icu::GregorianCalendar::yearLength
int32_t yearLength() const
return the length of the year field.
icu::GregorianCalendar::clone
virtual GregorianCalendar * clone() const override
Create and return a polymorphic copy of this calendar.
icu::GregorianCalendar::handleGetYearLength
virtual int32_t handleGetYearLength(int32_t eyear) const override
Return the number of days in the given extended year of this calendar system.
icu::GregorianCalendar::getActualMinimum
int32_t getActualMinimum(EDateFields field) const
Return the minimum value that this field could have, given the current date.
icu::GregorianCalendar::getStaticClassID
static UClassID getStaticClassID()
Return the class ID for this class.
icu::GregorianCalendar::isLeapYear
UBool isLeapYear(int32_t year) const
Return true if the given year is a leap year.
icu::GregorianCalendar::~GregorianCalendar
virtual ~GregorianCalendar()
Destructor.
icu::GregorianCalendar::handleGetExtendedYear
virtual int32_t handleGetExtendedYear(UErrorCode &status) override
Return the extended year defined by the current fields.
icu::GregorianCalendar::handleComputeMonthStart
virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth, UErrorCode &status) const override
Return the Julian day number of day before the first day of the given month in the given extended yea...
icu::GregorianCalendar::getActualMinimum
int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override
Return the minimum value that this field could have, given the current date.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode &success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the...
icu::GregorianCalendar::getActualMaximum
virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode &status) const override
Return the maximum value that this field could have, given the current date.
icu::GregorianCalendar::getEpochDay
virtual UDate getEpochDay(UErrorCode &status)
Return the day number with respect to the epoch.
icu::GregorianCalendar::isEquivalentTo
virtual UBool isEquivalentTo(const Calendar &other) const override
Returns true if the given Calendar object is equivalent to this one.
icu::GregorianCalendar::roll
virtual void roll(EDateFields field, int32_t amount, UErrorCode &status) override
(Overrides Calendar) Rolls up or down by the given amount in the specified field.
icu::GregorianCalendar::operator=
GregorianCalendar & operator=(const GregorianCalendar &right)
Default assignment operator.
icu::GregorianCalendar::roll
virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode &status) override
(Overrides Calendar) Rolls up or down by the given amount in the specified field.
icu::GregorianCalendar::handleGetMonthLength
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode &status) const override
Return the number of days in the given month of the given extended year of this calendar system.
icu::GregorianCalendar::GregorianCalendar
GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode &success)
Constructs a GregorianCalendar with the given AD date set in the default time zone with the default l...
icu::GregorianCalendar::setGregorianChange
void setGregorianChange(UDate date, UErrorCode &success)
Sets the GregorianCalendar change date.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::TimeZone
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
UCalendarDateFields
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
U_I18N_API
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316
UDate
double UDate
Date and Time data type.
Definition: utypes.h:218