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

GregorianCalendar Class Reference

Concrete class which provides the standard calendar used by most of the world. More...

#include <gregocal.h>

Inheritance diagram for GregorianCalendar::

Calendar UObject UMemory List of all members.

Public Types

enum  EEras { BC, AD }
 Useful constants for GregorianCalendar and TimeZone. More...


Public Methods

 GregorianCalendar (UErrorCode &success)
 Constructs a default GregorianCalendar using the current time in the default time zone with the default locale. More...

 GregorianCalendar (TimeZone *zoneToAdopt, UErrorCode &success)
 Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. More...

 GregorianCalendar (const TimeZone &zone, UErrorCode &success)
 Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. More...

 GregorianCalendar (const Locale &aLocale, UErrorCode &success)
 Constructs a GregorianCalendar based on the current time in the default time zone with the given locale. More...

 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. More...

 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. More...

 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 locale. More...

 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 default locale. More...

 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 default locale. More...

virtual ~GregorianCalendar ()
 Destructor. More...

 GregorianCalendar (const GregorianCalendar &source)
 Copy constructor. More...

GregorianCalendar & operator= (const GregorianCalendar &right)
 Default assignment operator. More...

virtual Calendarclone (void) const
 Create and return a polymorphic copy of this calendar. More...

void setGregorianChange (UDate date, UErrorCode &success)
 Sets the GregorianCalendar change date. More...

UDate getGregorianChange (void) const
 Gets the Gregorian Calendar change date. More...

UBool isLeapYear (int32_t year) const
 Return true if the given year is a leap year. More...

virtual UBool isEquivalentTo (const Calendar &other) const
 Returns TRUE if the given Calendar object is equivalent to this one. More...

virtual void add (EDateFields field, int32_t amount, UErrorCode &status)
 (Overrides Calendar) UDate Arithmetic function. More...

virtual void add (UCalendarDateFields field, int32_t amount, UErrorCode &status)
 (Overrides Calendar) UDate Arithmetic function. More...

virtual void roll (EDateFields field, int32_t amount, UErrorCode &status)
 (Overrides Calendar) Rolls up or down by the given amount in the specified field. More...

virtual void roll (UCalendarDateFields field, int32_t amount, UErrorCode &status)
 (Overrides Calendar) Rolls up or down by the given amount in the specified field. More...

virtual int32_t getMinimum (EDateFields field) const
 (Overrides Calendar) Returns minimum value for the given field. More...

virtual int32_t getMinimum (UCalendarDateFields field) const
 (Overrides Calendar) Returns minimum value for the given field. More...

virtual int32_t getMaximum (EDateFields field) const
 (Overrides Calendar) Returns maximum value for the given field. More...

virtual int32_t getMaximum (UCalendarDateFields field) const
 (Overrides Calendar) Returns maximum value for the given field. More...

virtual int32_t getGreatestMinimum (EDateFields field) const
 (Overrides Calendar) Returns highest minimum value for the given field if varies. More...

virtual int32_t getGreatestMinimum (UCalendarDateFields field) const
 (Overrides Calendar) Returns highest minimum value for the given field if varies. More...

virtual int32_t getLeastMaximum (EDateFields field) const
 (Overrides Calendar) Returns lowest maximum value for the given field if varies. More...

virtual int32_t getLeastMaximum (UCalendarDateFields field) const
 (Overrides Calendar) Returns lowest maximum value for the given field if varies. More...

int32_t getActualMinimum (EDateFields field) const
 Return the minimum value that this field could have, given the current date. More...

int32_t getActualMinimum (UCalendarDateFields field) const
 Return the minimum value that this field could have, given the current date. More...

int32_t getActualMaximum (EDateFields field) const
 Return the maximum value that this field could have, given the current date. More...

int32_t getActualMaximum (UCalendarDateFields field) const
 Return the maximum value that this field could have, given the current date. More...

virtual UBool inDaylightTime (UErrorCode &status) const
 (Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time. More...

virtual UClassID getDynamicClassID (void) const
 Override Calendar Returns a unique class ID POLYMORPHICALLY. More...

virtual const char * getType () const
 Get the calendar type, "gregorian", for use in DateFormatSymbols. More...

virtual UBool haveDefaultCentury () const
virtual UDate defaultCenturyStart () const
virtual int32_t defaultCenturyStartYear () const

Static Public Methods

UClassID getStaticClassID (void)
 Return the class ID for this class. More...


Protected Methods

virtual int32_t getGregorianYear (UErrorCode &status) const
 Called by computeFields. More...

virtual int32_t getDefaultMonthInYear () const
 Called by computeJulianDay. More...

virtual int32_t getDefaultDayInMonth (int32_t) const
 Called by computeJulianDay. More...

virtual void computeFields (UErrorCode &status)
 (Overrides Calendar) Converts GMT as milliseconds to time field values. More...

virtual void computeTime (UErrorCode &status)
 (Overrides Calendar) Converts Calendar's time field values to GMT as milliseconds. More...

virtual int32_t internalGetEra () const
 Return the ERA. More...

virtual int32_t monthLength (int32_t month) const
 return the length of the given month. More...

virtual int32_t monthLength (int32_t month, int32_t year) const
 return the length of the month according to the given year. More...

int32_t yearLength (int32_t year) const
 return the length of the given year. More...

int32_t yearLength (void) const
 return the length of the year field. More...

void pinDayOfMonth (void)
 After adjustments such as add(MONTH), add(YEAR), we don't want the month to jump around. More...

virtual UDate getEpochDay (UErrorCode &status)
 Return the day number with respect to the epoch. More...

virtual void timeToFields (UDate theTime, UBool quick, UErrorCode &status)
 Compute the date-based fields given the milliseconds since the epoch start. More...


Private Methods

 GregorianCalendar ()
int32_t computeRelativeDOW () const
 Compute the day of week, relative to the first day of week, from 0..6, of the current DOW_LOCAL or DAY_OF_WEEK fields. More...

int32_t computeRelativeDOW (double julianDay) const
 Compute the day of week, relative to the first day of week, from 0..6 of the given julian day. More...

int32_t computeDOYfromWOY (double julianDayOfYear) const
 Compute the DOY using the WEEK_OF_YEAR field and the julian day of the day BEFORE January 1 of a year (a return value from computeJulianDayOfYear). More...

double computeJulianDay (UBool isGregorian, int32_t year)
 Compute the Julian day number under either the Gregorian or the Julian calendar, using the given year and the remaining fields. More...

int32_t weekNumber (int32_t date, int32_t day)
 Return the week number of a day, within a period. More...

UBool validateFields (void) const
 Validates the values of the set time fields. More...

UBool boundsCheck (int32_t value, UCalendarDateFields field) const
 Validates the value of the given time field. More...

int32_t aggregateStamp (int32_t stamp_a, int32_t stamp_b)
 Return the pseudo-time-stamp for two fields, given their individual pseudo-time-stamps. More...

UDate internalGetDefaultCenturyStart (void) const
 Returns the beginning date of the 100-year window that dates with 2-digit years are considered to fall within. More...

int32_t internalGetDefaultCenturyStartYear (void) const
 Returns the first year of the 100-year window that dates with 2-digit years are considered to fall within. More...


Static Private Methods

double computeJulianDayOfYear (UBool isGregorian, int32_t year, UBool &isLeap)
 Compute the julian day number of the given year. More...

double millisToJulianDay (UDate millis)
 Converts time as milliseconds to Julian date. More...

UDate julianDayToMillis (double julian)
 Converts Julian date to time as milliseconds. More...

uint8_t julianDayToDayOfWeek (double julian)
 Convert a quasi Julian date to the day of the week. More...

double floorDivide (double numerator, double denominator)
 Divide two long integers, returning the floor of the quotient. More...

int32_t floorDivide (int32_t numerator, int32_t denominator)
 Divide two integers, returning the floor of the quotient. More...

int32_t floorDivide (int32_t numerator, int32_t denominator, int32_t remainder[])
 Divide two integers, returning the floor of the quotient, and the modulus remainder. More...

int32_t floorDivide (double numerator, int32_t denominator, int32_t remainder[])
 Divide two integers, returning the floor of the quotient, and the modulus remainder. More...

void initializeSystemDefaultCentury (void)
 Initializes the 100-year window that dates with 2-digit years are considered to fall within so that its start date is 80 years before the current time. More...


Private Attributes

UDate fGregorianCutover
 The point at which the Gregorian calendar rules are used, measured in milliseconds from the standard epoch. More...

UDate fNormalizedGregorianCutover
 Midnight, local time (using this Calendar's TimeZone) at or before the gregorianCutover. More...

int32_t fGregorianCutoverYear
 The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc. More...


Static Private Attributes

const char fgClassID
UDate fgSystemDefaultCenturyStart
 The system maintains a static default century start date. More...

int32_t fgSystemDefaultCenturyStartYear
 See documentation for systemDefaultCenturyStart. More...

const int32_t fgSystemDefaultCenturyYear
 Default value that indicates the defaultCenturyStartYear is unitialized. More...


Detailed Description

Concrete class which provides the standard calendar used by most of the world.

The standard (Gregorian) calendar has 2 eras, BC and AD.

This implementation handles a single discontinuity, which corresponds by default to the date the Gregorian calendar was originally instituted (October 15, 1582). Not all countries adopted the Gregorian calendar then, so this cutover date may be changed by the caller.

Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To avoid confusion, this Calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.

Values calculated for the WEEK_OF_YEAR field range from 1 to 53. Week 1 for a year is the first week that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).

For example, January 1, 1998 was a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997.

Example for using GregorianCalendar:

 
     // get the supported ids for GMT-08:00 (Pacific Standard Time)
     int32_t idsCount;
     const UnicodeString** ids = TimeZone::createAvailableIDs(-8 * 60 * 60 * 1000, idsCount);
     // if no ids were returned, something is wrong. get out.
     if (idsCount == 0) {
         return;
     }

     // begin output
     cout << "Current Time" << endl;

     // create a Pacific Standard Time time zone
     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *(ids[0]));

     // set up rules for daylight savings time
     pdt->setStartRule(Calendar::APRIL, 1, Calendar::SUNDAY, 2 * 60 * 60 * 1000);
     pdt->setEndRule(Calendar::OCTOBER, -1, Calendar::SUNDAY, 2 * 60 * 60 * 1000);

     // create a GregorianCalendar with the Pacific Daylight time zone
     // and the current date and time
     UErrorCode success = U_ZERO_ERROR;
     Calendar* calendar = new GregorianCalendar( pdt, success );

     // print out a bunch of interesting things
     cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl;
     cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl;
     cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl;
     cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl;
     cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl;
     cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl;
     cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl;
     cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl;
     cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl;
     cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl;

     cout << "Current Time, with hour reset to 3" << endl;
     calendar->clear(Calendar::HOUR_OF_DAY); // so doesn't override
     calendar->set(Calendar::HOUR, 3);
     cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl;
     cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl;
     cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl;
     cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl;
     cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl;
     cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl;
     cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl;
     cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl;
     cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
     cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl; // in hours

     delete[] ids;
     delete calendar; // also deletes pdt
Stable:
ICU 2.0

Definition at line 139 of file gregocal.h.


Member Enumeration Documentation

enum GregorianCalendar::EEras
 

Useful constants for GregorianCalendar and TimeZone.

Stable:
ICU 2.0
Enumeration values:
BC 
AD 

Definition at line 146 of file gregocal.h.


Constructor & Destructor Documentation

GregorianCalendar::GregorianCalendar UErrorCode   success
 

Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.

Parameters:
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

GregorianCalendar::GregorianCalendar TimeZone   zoneToAdopt,
UErrorCode   success
 

Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.

Clients are no longer responsible for deleting the given time zone object after it's adopted.

Parameters:
zoneToAdopt  The given timezone.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

GregorianCalendar::GregorianCalendar const TimeZone   zone,
UErrorCode   success
 

Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.

Parameters:
zone  The given timezone.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

GregorianCalendar::GregorianCalendar const Locale   aLocale,
UErrorCode   success
 

Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.

Parameters:
aLocale  The given locale.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

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.

Clients are no longer responsible for deleting the given time zone object after it's adopted.

Parameters:
zoneToAdopt  The given timezone.
aLocale  The given locale.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

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.

Parameters:
zone  The given timezone.
aLocale  The given locale.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

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 locale.

Parameters:
year  The value used to set the YEAR time field in the calendar.
month  The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date  The value used to set the DATE time field in the calendar.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

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 default locale.

Parameters:
year  The value used to set the YEAR time field in the calendar.
month  The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date  The value used to set the DATE time field in the calendar.
hour  The value used to set the HOUR_OF_DAY time field in the calendar.
minute  The value used to set the MINUTE time field in the calendar.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

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 default locale.

Parameters:
year  The value used to set the YEAR time field in the calendar.
month  The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date  The value used to set the DATE time field in the calendar.
hour  The value used to set the HOUR_OF_DAY time field in the calendar.
minute  The value used to set the MINUTE time field in the calendar.
second  The value used to set the SECOND time field in the calendar.
success  Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.
Stable:
ICU 2.0

virtual GregorianCalendar::~GregorianCalendar   [virtual]
 

Destructor.

Stable:
ICU 2.0

GregorianCalendar::GregorianCalendar const GregorianCalendar &    source
 

Copy constructor.

Parameters:
source  the object to be copied.
Stable:
ICU 2.0

GregorianCalendar::GregorianCalendar   [private]
 


Member Function Documentation

virtual void GregorianCalendar::add UCalendarDateFields    field,
int32_t    amount,
UErrorCode   status
[virtual]
 

(Overrides Calendar) UDate Arithmetic function.

Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For more information, see the documentation for Calendar::add().

Parameters:
field  The time field.
amount  The amount of date or time to be added to the field.
status  Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual void GregorianCalendar::add EDateFields    field,
int32_t    amount,
UErrorCode   status
[virtual]
 

(Overrides Calendar) UDate Arithmetic function.

Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For more information, see the documentation for Calendar::add().

Parameters:
field  The time field.
amount  The amount of date or time to be added to the field.
status  Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.
Deprecated:
ICU 2.6. Use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.

Reimplemented from Calendar.

int32_t GregorianCalendar::aggregateStamp int32_t    stamp_a,
int32_t    stamp_b
[private]
 

Return the pseudo-time-stamp for two fields, given their individual pseudo-time-stamps.

If either of the fields is unset, then the aggregate is unset. Otherwise, the aggregate is the later of the two stamps.

Parameters:
stamp_a  One given field.
stamp_b  Another given field.
Returns:
the pseudo-time-stamp for two fields

UBool GregorianCalendar::boundsCheck int32_t    value,
UCalendarDateFields    field
const [private]
 

Validates the value of the given time field.

True if it's valid.

virtual Calendar* GregorianCalendar::clone void    const [virtual]
 

Create and return a polymorphic copy of this calendar.

Returns:
return a polymorphic copy of this calendar.
Stable:
ICU 2.0

Reimplemented from Calendar.

int32_t GregorianCalendar::computeDOYfromWOY double    julianDayOfYear const [private]
 

Compute the DOY using the WEEK_OF_YEAR field and the julian day of the day BEFORE January 1 of a year (a return value from computeJulianDayOfYear).

Parameters:
julianDayOfYear  the given julian day of the day BEFORE January 1 of a year.
Returns:
the DOY using the WEEK_OF_YEAR field.

virtual void GregorianCalendar::computeFields UErrorCode   status [protected, virtual]
 

(Overrides Calendar) Converts GMT as milliseconds to time field values.

Parameters:
status  Fill-in parameter which receives the status of this operation.
Stable:
ICU 2.0

Reimplemented from Calendar.

double GregorianCalendar::computeJulianDay UBool    isGregorian,
int32_t    year
[private]
 

Compute the Julian day number under either the Gregorian or the Julian calendar, using the given year and the remaining fields.

Parameters:
isGregorian  if true, use the Gregorian calendar
year  the adjusted year number, with 0 indicating the year 1 BC, -1 indicating 2 BC, etc.
Returns:
the Julian day number

double GregorianCalendar::computeJulianDayOfYear UBool    isGregorian,
int32_t    year,
UBool   isLeap
[static, private]
 

Compute the julian day number of the given year.

Parameters:
isGregorian  if true, using Gregorian calendar, otherwise using Julian calendar
year  the given year.
isLeap  true if the year is a leap year.
Returns:

int32_t GregorianCalendar::computeRelativeDOW double    julianDay const [private]
 

Compute the day of week, relative to the first day of week, from 0..6 of the given julian day.

Parameters:
julianDay  the given julian day.
Returns:
the day of week, relative to the first day of week.

int32_t GregorianCalendar::computeRelativeDOW   const [private]
 

Compute the day of week, relative to the first day of week, from 0..6, of the current DOW_LOCAL or DAY_OF_WEEK fields.

This is equivalent to get(DOW_LOCAL) - 1.

Returns:
the day of week, relative to the first day of week.

virtual void GregorianCalendar::computeTime UErrorCode   status [protected, virtual]
 

(Overrides Calendar) Converts Calendar's time field values to GMT as milliseconds.

Parameters:
status  Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.
Stable:
ICU 2.0

Reimplemented from Calendar.

virtual UDate GregorianCalendar::defaultCenturyStart   const [virtual]
 

Internal:
Returns:
the start of the default century

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::defaultCenturyStartYear   const [virtual]
 

Internal:
Returns:
the beginning year of the default century

Reimplemented from Calendar.

int32_t GregorianCalendar::floorDivide double    numerator,
int32_t    denominator,
int32_t    remainder[]
[static, private]
 

Divide two integers, returning the floor of the quotient, and the modulus remainder.

Unlike the built-in division, this is mathematically well-behaved. E.g., -1/4 => 0 and -14 => -1, but floorDivide(-1,4) => -1 with remainder[0] => 3.

Parameters:
numerator  the numerator
denominator  a divisor which must be > 0
remainder  an array of at least one element in which the value numerator mod denominator is returned. Unlike numerator % denominator, this will always be non-negative.
Returns:
the floor of the quotient.

int32_t GregorianCalendar::floorDivide int32_t    numerator,
int32_t    denominator,
int32_t    remainder[]
[static, private]
 

Divide two integers, returning the floor of the quotient, and the modulus remainder.

Unlike the built-in division, this is mathematically well-behaved. E.g., -1/4 => 0 and -14 => -1, but floorDivide(-1,4) => -1 with remainder[0] => 3.

Parameters:
numerator  the numerator
denominator  a divisor which must be > 0
remainder  an array of at least one element in which the value numerator mod denominator is returned. Unlike numerator % denominator, this will always be non-negative.
Returns:
the floor of the quotient.

int32_t GregorianCalendar::floorDivide int32_t    numerator,
int32_t    denominator
[static, private]
 

Divide two integers, returning the floor of the quotient.

Unlike the built-in division, this is mathematically well-behaved. E.g., -1/4 => 0 but floorDivide(-1,4) => -1.

Parameters:
numerator  the numerator
denominator  a divisor which must be > 0
Returns:
the floor of the quotient.

double GregorianCalendar::floorDivide double    numerator,
double    denominator
[static, private]
 

Divide two long integers, returning the floor of the quotient.

Unlike the built-in division, this is mathematically well-behaved. E.g., -1/4 => 0 but floorDivide(-1,4) => -1.

Parameters:
numerator  the numerator
denominator  a divisor which must be > 0
Returns:
the floor of the quotient.

int32_t GregorianCalendar::getActualMaximum UCalendarDateFields    field const
 

Return the maximum value that this field could have, given the current date.

For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

Parameters:
field  the time field.
Returns:
the maximum value that this field could have, given the current date.
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

int32_t GregorianCalendar::getActualMaximum EDateFields    field const
 

Return the maximum value that this field could have, given the current date.

For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

Parameters:
field  the time field.
Returns:
the maximum value that this field could have, given the current date.
Deprecated:
ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.

int32_t GregorianCalendar::getActualMinimum UCalendarDateFields    field const
 

Return the minimum value that this field could have, given the current date.

For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().

Parameters:
field  the time field.
Returns:
the minimum value that this field could have, given the current date.
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

int32_t GregorianCalendar::getActualMinimum EDateFields    field const
 

Return the minimum value that this field could have, given the current date.

For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().

Parameters:
field  the time field.
Returns:
the minimum value that this field could have, given the current date.
Deprecated:
ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.

virtual int32_t GregorianCalendar::getDefaultDayInMonth int32_t    const [inline, protected, virtual]
 

Called by computeJulianDay.

Returns the default day (1-based) for the month, taking currently-set year and era into account. Defaults to 1 for Gregorian, which doesn't care.

Internal:
For internal use only.

Definition at line 579 of file gregocal.h.

virtual int32_t GregorianCalendar::getDefaultMonthInYear   const [inline, protected, virtual]
 

Called by computeJulianDay.

Returns the default month (0-based) for the year, taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.

Internal:
For internal use only.

Definition at line 571 of file gregocal.h.

UClassID GregorianCalendar::getDynamicClassID void    const [inline, virtual]
 

Override Calendar Returns a unique class ID POLYMORPHICALLY.

Pure virtual override. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.

Returns:
The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.
Stable:
ICU 2.0

Reimplemented from Calendar.

Definition at line 942 of file gregocal.h.

virtual UDate GregorianCalendar::getEpochDay UErrorCode   status [protected, virtual]
 

Return the day number with respect to the epoch.

January 1, 1970 (Gregorian) is day zero.

Parameters:
status  Fill-in parameter which receives the status of this operation.
Returns:
the day number with respect to the epoch.
Internal:
For internal use only.

virtual int32_t GregorianCalendar::getGreatestMinimum UCalendarDateFields    field const [virtual]
 

(Overrides Calendar) Returns highest minimum value for the given field if varies.

Otherwise same as getMinimum(). For Gregorian, no difference.

Parameters:
field  the time field.
Returns:
highest minimum value for the given field if varies. Otherwise same as getMinimum().
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getGreatestMinimum EDateFields    field const [virtual]
 

(Overrides Calendar) Returns highest minimum value for the given field if varies.

Otherwise same as getMinimum(). For Gregorian, no difference.

Parameters:
field  the time field.
Returns:
highest minimum value for the given field if varies. Otherwise same as getMinimum().
Deprecated:
ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.

Reimplemented from Calendar.

UDate GregorianCalendar::getGregorianChange void    const
 

Gets the Gregorian Calendar change date.

This is the point when the switch from Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 15, 1582. Previous to this time and date will be Julian dates.

Returns:
The Gregorian cutover time for this calendar.
Stable:
ICU 2.0

virtual int32_t GregorianCalendar::getGregorianYear UErrorCode   status const [protected, virtual]
 

Called by computeFields.

Converts calendar's year into Gregorian Extended Year (where negative = BC)

Returns:
Current year in Gregorian years, where -3 means 4 BC (1-bcyear)
Internal:
For internal use only.

virtual int32_t GregorianCalendar::getLeastMaximum UCalendarDateFields    field const [virtual]
 

(Overrides Calendar) Returns lowest maximum value for the given field if varies.

Otherwise same as getMaximum(). For Gregorian DAY_OF_MONTH, 28.

Parameters:
field  the time field.
Returns:
lowest maximum value for the given field if varies. Otherwise same as getMaximum().
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getLeastMaximum EDateFields    field const [virtual]
 

(Overrides Calendar) Returns lowest maximum value for the given field if varies.

Otherwise same as getMaximum(). For Gregorian DAY_OF_MONTH, 28.

Parameters:
field  the time field.
Returns:
lowest maximum value for the given field if varies. Otherwise same as getMaximum().
Deprecated:
ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getMaximum UCalendarDateFields    field const [virtual]
 

(Overrides Calendar) Returns maximum value for the given field.

e.g. for Gregorian DAY_OF_MONTH, 31.

Parameters:
field  the time field.
Returns:
maximum value for the given field
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getMaximum EDateFields    field const [virtual]
 

(Overrides Calendar) Returns maximum value for the given field.

e.g. for Gregorian DAY_OF_MONTH, 31.

Parameters:
field  the time field.
Returns:
maximum value for the given field
Deprecated:
ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getMinimum UCalendarDateFields    field const [virtual]
 

(Overrides Calendar) Returns minimum value for the given field.

e.g. for Gregorian DAY_OF_MONTH, 1.

Parameters:
field  the time field.
Returns:
minimum value for the given field
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual int32_t GregorianCalendar::getMinimum EDateFields    field const [virtual]
 

(Overrides Calendar) Returns minimum value for the given field.

e.g. for Gregorian DAY_OF_MONTH, 1.

Parameters:
field  the time field.
Returns:
minimum value for the given field
Deprecated:
ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.

Reimplemented from Calendar.

UClassID GregorianCalendar::getStaticClassID void    [inline, static]
 

Return the class ID for this class.

This is useful only for comparing to a return value from getDynamicClassID(). For example:

Base* polymorphic_pointer = createPolymorphicObject(); if (polymorphic_pointer->getDynamicClassID() == Derived::getStaticClassID()) ...

Returns:
The class ID for all objects of this class.
Stable:
ICU 2.0

Definition at line 938 of file gregocal.h.

Referenced by getDynamicClassID().

virtual const char* GregorianCalendar::getType void    const [virtual]
 

Get the calendar type, "gregorian", for use in DateFormatSymbols.

Returns:
calendar type
Internal:
For internal use only.

Reimplemented from Calendar.

virtual UBool GregorianCalendar::haveDefaultCentury   const [virtual]
 

Internal:
Returns:
TRUE if this calendar has the notion of a default century

Reimplemented from Calendar.

virtual UBool GregorianCalendar::inDaylightTime UErrorCode   status const [virtual]
 

(Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time.

Recognizes DST_OFFSET, if it is set.

Parameters:
status  Fill-in parameter which receives the status of this operation.
Returns:
True if the current date for this Calendar is in Daylight Savings Time, false, otherwise.
Stable:
ICU 2.0

Reimplemented from Calendar.

void GregorianCalendar::initializeSystemDefaultCentury void    [static, private]
 

Initializes the 100-year window that dates with 2-digit years are considered to fall within so that its start date is 80 years before the current time.

UDate GregorianCalendar::internalGetDefaultCenturyStart void    const [private]
 

Returns the beginning date of the 100-year window that dates with 2-digit years are considered to fall within.

Returns:
the beginning date of the 100-year window that dates with 2-digit years are considered to fall within.

int32_t GregorianCalendar::internalGetDefaultCenturyStartYear void    const [private]
 

Returns the first year of the 100-year window that dates with 2-digit years are considered to fall within.

Returns:
the first year of the 100-year window that dates with 2-digit years are considered to fall within.

virtual int32_t GregorianCalendar::internalGetEra   const [protected, virtual]
 

Return the ERA.

We need a special method for this because the default ERA is AD, but a zero (unset) ERA is BC.

Returns:
the ERA.
Internal:
For internal use only.

virtual UBool GregorianCalendar::isEquivalentTo const Calendar   other const [virtual]
 

Returns TRUE if the given Calendar object is equivalent to this one.

Calendar override.

Parameters:
other  the Calendar to be compared with this Calendar
Draft:
This API has been introduced in ICU 2.4. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

UBool GregorianCalendar::isLeapYear int32_t    year const
 

Return true if the given year is a leap year.

Determination of whether a year is a leap year is actually very complicated. We do something crude and mostly correct here, but for a real determination you need a lot of contextual information. For example, in Sweden, the change from Julian to Gregorian happened in a complex way resulting in missed leap years and double leap years between 1700 and 1753. Another example is that after the start of the Julian calendar in 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these quirks, and pays attention only to the Julian onset date and the Gregorian cutover (which can be changed).

Parameters:
year  The given year.
Returns:
True if the given year is a leap year; false otherwise.
Stable:
ICU 2.0

uint8_t GregorianCalendar::julianDayToDayOfWeek double    julian [inline, static, private]
 

Convert a quasi Julian date to the day of the week.

The Julian date used here is not a true Julian date, since it is measured from midnight, not noon. Return value is one-based.

Parameters:
julian  The given Julian date number.
Returns:
Day number from 1..7 (SUN..SAT).

Definition at line 945 of file gregocal.h.

UDate GregorianCalendar::julianDayToMillis double    julian [static, private]
 

Converts Julian date to time as milliseconds.

The Julian date used here is not a true Julian date, since it is measured from midnight, not noon.

Parameters:
julian  The given Julian date number.
Returns:
Time as milliseconds.

double GregorianCalendar::millisToJulianDay UDate    millis [static, private]
 

Converts time as milliseconds to Julian date.

The Julian date used here is not a true Julian date, since it is measured from midnight, not noon.

Parameters:
millis  The given milliseconds.
Returns:
The Julian date number.

virtual int32_t GregorianCalendar::monthLength int32_t    month,
int32_t    year
const [protected, virtual]
 

return the length of the month according to the given year.

Parameters:
month  the given month.
year  the given year.
Returns:
the length of the month
Internal:
For internal use only.

virtual int32_t GregorianCalendar::monthLength int32_t    month const [protected, virtual]
 

return the length of the given month.

Parameters:
month  the given month.
Returns:
the length of the given month.
Internal:
For internal use only.

GregorianCalendar& GregorianCalendar::operator= const GregorianCalendar &    right
 

Default assignment operator.

Parameters:
right  the object to be copied.
Stable:
ICU 2.0

void GregorianCalendar::pinDayOfMonth void    [protected]
 

After adjustments such as add(MONTH), add(YEAR), we don't want the month to jump around.

E.g., we don't want Jan 31 + 1 month to go to Mar 3, we want it to go to Feb 28. Adjustments which might run into this problem call this method to retain the proper month.

Internal:
For internal use only.

virtual void GregorianCalendar::roll UCalendarDateFields    field,
int32_t    amount,
UErrorCode   status
[virtual]
 

(Overrides Calendar) Rolls up or down by the given amount in the specified field.

For more information, see the documentation for Calendar::roll().

Parameters:
field  The time field.
amount  Indicates amount to roll.
status  Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.
Draft:
This API has been introduced in ICU 2.6.. It is still in draft state and may be modified in a future release.

Reimplemented from Calendar.

virtual void GregorianCalendar::roll EDateFields    field,
int32_t    amount,
UErrorCode   status
[virtual]
 

(Overrides Calendar) Rolls up or down by the given amount in the specified field.

For more information, see the documentation for Calendar::roll().

Parameters:
field  The time field.
amount  Indicates amount to roll.
status  Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.
Deprecated:
ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.

Reimplemented from Calendar.

void GregorianCalendar::setGregorianChange UDate    date,
UErrorCode   success
 

Sets the GregorianCalendar change date.

This is the point when the switch from Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 15, 1582. Previous to this time and date will be Julian dates.

Parameters:
date  The given Gregorian cutover date.
success  Output param set to success/failure code on exit.
Stable:
ICU 2.0

virtual void GregorianCalendar::timeToFields UDate    theTime,
UBool    quick,
UErrorCode   status
[protected, virtual]
 

Compute the date-based fields given the milliseconds since the epoch start.

Do not compute the time-based fields (HOUR, MINUTE, etc.).

Parameters:
theTime  the time in wall millis (either Standard or DST), whichever is in effect
quick  if true, only compute the ERA, YEAR, MONTH, DATE, DAY_OF_WEEK, and DAY_OF_YEAR.
status  Fill-in parameter which receives the status of this operation.
Internal:
For internal use only.

UBool GregorianCalendar::validateFields void    const [private]
 

Validates the values of the set time fields.

True if they're all valid.

Returns:
True if the set time fields are all valid.

int32_t GregorianCalendar::weekNumber int32_t    date,
int32_t    day
[private]
 

Return the week number of a day, within a period.

This may be the week number in a year, or the week number in a month. Usually this will be a value >= 1, but if some initial days of the period are excluded from week 1, because minimalDaysInFirstWeek is > 1, then the week number will be zero for those initial days. Requires the day of week for the given date in order to determine the day of week of the first day of the period.

Parameters:
date  Day-of-year or day-of-month. Should be 1 for first day of period.
day  Day-of-week for given dayOfPeriod. 1-based with 1=Sunday.
Returns:
Week number, one-based, or zero if the day falls in part of the month before the first week, when there are days before the first week because the minimum days in the first week is more than one.

int32_t GregorianCalendar::yearLength void    const [protected]
 

return the length of the year field.

Returns:
the length of the year field
Internal:
For internal use only.

int32_t GregorianCalendar::yearLength int32_t    year const [protected]
 

return the length of the given year.

Parameters:
year  the given year.
Returns:
the length of the given year.
Internal:
For internal use only.


Member Data Documentation

UDate GregorianCalendar::fGregorianCutover [private]
 

The point at which the Gregorian calendar rules are used, measured in milliseconds from the standard epoch.

Default is October 15, 1582 (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed by October 15, 1582 (Gregorian). This corresponds to Julian day number 2299161.

Definition at line 768 of file gregocal.h.

int32_t GregorianCalendar::fGregorianCutoverYear [private]
 

The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc.

Definition at line 781 of file gregocal.h.

UDate GregorianCalendar::fNormalizedGregorianCutover [private]
 

Midnight, local time (using this Calendar's TimeZone) at or before the gregorianCutover.

This is a pure date value with no time of day or timezone component.

Definition at line 775 of file gregocal.h.

const char GregorianCalendar::fgClassID [static, private]
 

Definition at line 783 of file gregocal.h.

UDate GregorianCalendar::fgSystemDefaultCenturyStart [static, private]
 

The system maintains a static default century start date.

This is initialized the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to indicate an uninitialized state. Once the system default century date and year are set, they do not change.

Definition at line 896 of file gregocal.h.

int32_t GregorianCalendar::fgSystemDefaultCenturyStartYear [static, private]
 

See documentation for systemDefaultCenturyStart.

Definition at line 901 of file gregocal.h.

const int32_t GregorianCalendar::fgSystemDefaultCenturyYear [static, private]
 

Default value that indicates the defaultCenturyStartYear is unitialized.

Definition at line 906 of file gregocal.h.


The documentation for this class was generated from the following file:
Generated on Thu Jun 12 13:11:16 2003 for ICU 2.6 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001