rwlogo
Rogue Wave Views 5.6

Rogue Wave Views
Foundation Package API Reference Guide

Product Documentation:

Rogue Wave Views
Documentation Home

IlGregorianCalendar Class Reference

Class that provides the standard calendar used by most of the world. More...

#include <ilog/gregocal.h>

Inheritance diagram for IlGregorianCalendar:
IlCalendar

List of all members.

Public Types

enum  EEras { BC, AD }
 

Useful constants for IlGregorianCalendar and IlTimeZone.

More...

Public Member Functions

 IlGregorianCalendar (const IlGregorianCalendar &source)
 Copy constructor.
 IlGregorianCalendar (IlInt year, IlInt month, IlInt date, IlInt hour, IlInt minute, IlInt second, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given AD date and time.
 IlGregorianCalendar (IlInt year, IlInt month, IlInt date, IlInt hour, IlInt minute, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given AD date and time.
 IlGregorianCalendar (IlInt year, IlInt month, IlInt date, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given AD date.
 IlGregorianCalendar (const IlTimeZone &zone, const IlLocale &aLocale, IlDateErrorCode &success)
 Constructs a IlGregorianCalendar in the given time zone with the given locale.
 IlGregorianCalendar (IlTimeZone *zoneToAdopt, const IlLocale &aLocale, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given time zone and locale.
 IlGregorianCalendar (const IlLocale &aLocale, IlDateErrorCode &success)
 Constructs a IlGregorianCalendar with the given locale.
 IlGregorianCalendar (const IlTimeZone &zone, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given time zone.
 IlGregorianCalendar (IlTimeZone *zoneToAdopt, IlDateErrorCode &success)
 Constructs an IlGregorianCalendar with the given time zone.
 IlGregorianCalendar (IlDateErrorCode &success)
 Constructs a default IlGregorianCalendar.
virtual ~IlGregorianCalendar ()
 Destructor.
virtual void add (IlDateFields field, IlInt amount, IlDateErrorCode &status)
 Adds the specified (signed) amount of time to the given time field, based on the calendar rules.
virtual IlCalendarclone (void) const
 Creates and returns a polymorphic copy of this calendar.
virtual IlBoolean equivalentTo (const IlCalendar &other) const
 IlCalendar override.
IlInt getActualMaximum (IlDateFields field) const
 Returns the maximum value that this field could have, given the current date.
IlInt getActualMinimum (IlDateFields field) const
 Returns the minimum value that this field could have, given the current date.
virtual IlInt getGreatestMinimum (IlDateFields field) const
 Returns the highest minimum value for the given field if varies.
IlDate getGregorianChange (void) const
 Gets the IlGregorianCalendar change date.
virtual IlInt getLeastMaximum (IlDateFields field) const
 Returns the lowest maximum value for the given field if varies.
virtual IlInt getMaximum (IlDateFields field) const
 Returns the maximum value for the given field.
virtual IlInt getMinimum (IlDateFields field) const
 Returns the minimum value for the given field.
virtual IlBoolean inDaylightTime (IlDateErrorCode &status) const
 Returns IlTrue if the current date for this IlCalendar is in Daylight Savings Time.
IlBoolean isLeapYear (IlInt year) const
 Returns IlTrue if the given year is a leap year.
IlGregorianCalendaroperator= (const IlGregorianCalendar &right)
 Default assignment operator.
virtual IlBoolean operator== (const IlCalendar &that) const
 Compares the equality of two IlGregorianCalendar objects.
virtual void roll (IlDateFields field, IlInt amount, IlDateErrorCode &status)
 Rolls up or down by the given amount in the specified field.
void setGregorianChange (IlDate date, IlDateErrorCode &success)
 Sets the IlGregorianCalendar change date.

Protected Member Functions

virtual void computeFields (IlDateErrorCode &status)
 Converts GMT as milliseconds to time field values.
virtual void computeTime (IlDateErrorCode &status)
 Converts IlCalendar time field values to GMT as milliseconds.

Detailed Description

Class that provides the standard calendar used by most of the world.

Library: ilog

From IBM ICU classes, adapted for Rogue Wave Views libraries.
Copyright (C) 1997-1999, International Business Machines Corporation and others. All Rights Reserved.

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 IlCalendar 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 IlGregorianCalendar:

     // get the supported ids for GMT-08:00 (Pacific Standard Time)
     IlInt idsCount;
     const UnicodeString** ids =
         IlTimeZone::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(IlCalendar::APRIL, 1, IlCalendar::SUNDAY, 2 * 60 * 60 * 1000);
     pdt->setEndRule(IlCalendar::OCTOBER, -1, IlCalendar::SUNDAY, 2 * 60 * 60 * 1000);
     // create a IlGregorianCalendar with the Pacific Daylight time zone
     // and the current date and time
     IlDateErrorCode success = IL_DATE_ZERO_ERROR;
     IlCalendar* calendar = new IlGregorianCalendar(pdt, success);
     // print out a bunch of interesting things
     cout << "ERA: " << calendar->get(IlCalendar::ERA, success) << endl;
     cout << "YEAR: " << calendar->get(IlCalendar::YEAR, success) << endl;
     cout << "MONTH: " << calendar->get(IlCalendar::MONTH, success) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get(IlCalendar::WEEK_OF_YEAR, success) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get(IlCalendar::WEEK_OF_MONTH, success) << endl;
     cout << "DATE: " << calendar->get(IlCalendar::DATE, success) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get(IlCalendar::DAY_OF_MONTH, success) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get(IlCalendar::DAY_OF_YEAR, success) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get(IlCalendar::DAY_OF_WEEK, success) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get(IlCalendar::DAY_OF_WEEK_IN_MONTH, success) << endl;
     cout << "AM_PM: " << calendar->get(IlCalendar::AM_PM, success) << endl;
     cout << "HOUR: " << calendar->get(IlCalendar::HOUR, success) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get(IlCalendar::HOUR_OF_DAY, success) << endl;
     cout << "MINUTE: " << calendar->get(IlCalendar::MINUTE, success) << endl;
     cout << "SECOND: " << calendar->get(IlCalendar::SECOND, success) << endl;
     cout << "MILLISECOND: " << calendar->get(IlCalendar::MILLISECOND, success) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get(IlCalendar::ZONE_OFFSET, success)/(60*60*1000)) << endl;
     cout << "DST_OFFSET: " << (calendar->get(IlCalendar::DST_OFFSET, success)/(60*60*1000)) << endl;
     cout << "Current Time, with hour reset to 3" << endl;
     calendar->clear(IlCalendar::HOUR_OF_DAY); // so doesn't override
     calendar->set(IlCalendar::HOUR, 3);
     cout << "ERA: " << calendar->get(IlCalendar::ERA, success) << endl;
     cout << "YEAR: " << calendar->get(IlCalendar::YEAR, success) << endl;
     cout << "MONTH: " << calendar->get(IlCalendar::MONTH, success) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get(IlCalendar::WEEK_OF_YEAR, success) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get(IlCalendar::WEEK_OF_MONTH, success) << endl;
     cout << "DATE: " << calendar->get(IlCalendar::DATE, success) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get(IlCalendar::DAY_OF_MONTH, success) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get(IlCalendar::DAY_OF_YEAR, success) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get(IlCalendar::DAY_OF_WEEK, success) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get(IlCalendar::DAY_OF_WEEK_IN_MONTH, success) << endl;
     cout << "AM_PM: " << calendar->get(IlCalendar::AM_PM, success) << endl;
     cout << "HOUR: " << calendar->get(IlCalendar::HOUR, success) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get(IlCalendar::HOUR_OF_DAY, success) << endl;
     cout << "MINUTE: " << calendar->get(IlCalendar::MINUTE, success) << endl;
     cout << "SECOND: " << calendar->get(IlCalendar::SECOND, success) << endl;
     cout << "MILLISECOND: " << calendar->get(IlCalendar::MILLISECOND, success) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get(IlCalendar::ZONE_OFFSET, success)/(60*60*1000)) << endl; // in hours
     cout << "DST_OFFSET: " << (calendar->get(IlCalendar::DST_OFFSET, success)/(60*60*1000)) << endl; // in hours
     delete[] ids;
     delete calendar; // also deletes pdt
 

Member Enumeration Documentation

Useful constants for IlGregorianCalendar and IlTimeZone.

Enumerator:
BC 

Used to specify a year before the supposed year of the birth of Christ.

AD 

Used to specify a year after the supposed year of the birth of Christ.


Constructor & Destructor Documentation

IlGregorianCalendar::IlGregorianCalendar ( IlDateErrorCode success  ) 

Constructs a default IlGregorianCalendar.

The object is constructed using the current time in the default time zone with the default locale.

Parameters:
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( IlTimeZone zoneToAdopt,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given time zone.

The object is 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 is adopted.

Parameters:
zoneToAdopt The given time zone.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( const IlTimeZone zone,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given time zone.

The object is based on the current time in the given time zone with the default locale.

Parameters:
zone The given time zone.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( const IlLocale &  aLocale,
IlDateErrorCode success 
)

Constructs a IlGregorianCalendar with the given locale.

The object is based on the current time in the default time zone.

Parameters:
aLocale The given locale.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( IlTimeZone zoneToAdopt,
const IlLocale &  aLocale,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given time zone and locale.

The object is based on the current time. Clients are no longer responsible for deleting the given time zone object after it is adopted.

Parameters:
zoneToAdopt The given time zone.
aLocale The given locale.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( const IlTimeZone zone,
const IlLocale &  aLocale,
IlDateErrorCode success 
)

Constructs a IlGregorianCalendar in the given time zone with the given locale.

The object is based on the current time.

Parameters:
zone The given time zone.
aLocale The given locale.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
IlGregorianCalendar::IlGregorianCalendar ( IlInt  year,
IlInt  month,
IlInt  date,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given AD date.

The object is 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. The month value is 0-based, for example, 0 for January.
date The value used to set the DATE time field in the calendar.
success Indicates the status of IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
Warning:
[note] This constructor does not check the date because the check can be dependent on the locale. To check the date, you must call the validateFields function. This function returns IlTrue if the date is valid.
IlGregorianCalendar::IlGregorianCalendar ( IlInt  year,
IlInt  month,
IlInt  date,
IlInt  hour,
IlInt  minute,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given AD date and time.

The object is 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. The month value is 0-based, for example, 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 IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
Warning:
[note] This constructor does not check the date because the check can be dependent on the locale. To check the date, you must call the validateFields function. This function returns IlTrue if the date is valid.
IlGregorianCalendar::IlGregorianCalendar ( IlInt  year,
IlInt  month,
IlInt  date,
IlInt  hour,
IlInt  minute,
IlInt  second,
IlDateErrorCode success 
)

Constructs an IlGregorianCalendar with the given AD date and time.

The object is 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. The month value is 0-based, for example, 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 IlGregorianCalendar object construction. Returns IL_DATE_ZERO_ERROR if constructed successfully.
Warning:
[note] This constructor does not check the date because the check can be dependent on the locale. To check the date, you must call the validateFields function. This function returns IlTrue if the date is valid.

Member Function Documentation

virtual void IlGregorianCalendar::add ( IlDateFields  field,
IlInt  amount,
IlDateErrorCode status 
) [virtual]

Adds the specified (signed) amount of time to the given time field, based on the calendar rules.

(Overrides IlCalendar) IlDate Arithmetic function.

Parameters:
field The time field.
amount The amount of date or time to be added to the field.
status The output param is set to success/failure code on exit. If any value previously set in the time field is invalid, it will be set to an error status.
See also:
IlCalendar::add().

Implements IlCalendar.

virtual void IlGregorianCalendar::computeFields ( IlDateErrorCode status  )  [protected, virtual]

Converts GMT as milliseconds to time field values.

(Overrides IlCalendar)

Implements IlCalendar.

virtual void IlGregorianCalendar::computeTime ( IlDateErrorCode status  )  [protected, virtual]

Converts IlCalendar time field values to GMT as milliseconds.

(Overrides IlCalendar)

Parameters:
status The output param set to success/failure code on exit. If any value previously set in the time field is invalid, it will be set to an error status.

Implements IlCalendar.

virtual IlBoolean IlGregorianCalendar::equivalentTo ( const IlCalendar other  )  const [virtual]

IlCalendar override.

Returns:
IlTrue if another IlCalendar object is equivalent to this one. An equivalent IlCalendar will behave exactly as this one does, but may be set to a different time.

Reimplemented from IlCalendar.

IlInt IlGregorianCalendar::getActualMaximum ( IlDateFields  field  )  const

Returns 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 is 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

IlInt IlGregorianCalendar::getActualMinimum ( IlDateFields  field  )  const

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

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

virtual IlInt IlGregorianCalendar::getGreatestMinimum ( IlDateFields  field  )  const [virtual]

Returns the highest minimum value for the given field if varies.

Otherwise it is the same as getMinimum(). For Gregorian, there is no difference. (Overrides IlCalendar)

Implements IlCalendar.

IlDate IlGregorianCalendar::getGregorianChange ( void   )  const

Gets the IlGregorianCalendar 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. Prior to this time and date are Julian dates.

Returns:
The Gregorian cutover time for this calendar.
virtual IlInt IlGregorianCalendar::getLeastMaximum ( IlDateFields  field  )  const [virtual]

Returns the lowest maximum value for the given field if varies.

Otherwise it is the same as getMaximum(). For Gregorian DAY_OF_MONTH, 28. (Overrides IlCalendar).

Implements IlCalendar.

virtual IlInt IlGregorianCalendar::getMaximum ( IlDateFields  field  )  const [virtual]

Returns the maximum value for the given field.

For example, for Gregorian DAY_OF_MONTH, 31. (Overrides IlCalendar).

Implements IlCalendar.

virtual IlInt IlGregorianCalendar::getMinimum ( IlDateFields  field  )  const [virtual]

Returns the minimum value for the given field.

For example, for Gregorian DAY_OF_MONTH, 1. (Overrides IlCalendar)

Implements IlCalendar.

virtual IlBoolean IlGregorianCalendar::inDaylightTime ( IlDateErrorCode status  )  const [virtual]

Returns IlTrue if the current date for this IlCalendar is in Daylight Savings Time.

Recognizes DST_OFFSET, if it is set. (Overrides IlCalendar)

Parameters:
status Fill-in parameter which receives the status of this operation.
Returns:
This parameter is set to IlTrue if the current date for this IlCalendar is in Daylight Savings Time. Otherwise, it is set to IlFalse.

Implements IlCalendar.

IlBoolean IlGregorianCalendar::isLeapYear ( IlInt  year  )  const

Returns IlTrue 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:
IlTrue if the given year is a leap year; IlFalse otherwise.
virtual IlBoolean IlGregorianCalendar::operator== ( const IlCalendar that  )  const [virtual]

Compares the equality of two IlGregorianCalendar objects.

Objects of different subclasses are considered unequal. This is a strict equality test.

See also:
IlCalendar::operator==()
Parameters:
that The IlGregorianCalendar object to be compared with.
Returns:
IlTrue if the given IlGregorianCalendar is the same as this IlGregorianCalendar, otherwise IlFalse.

Reimplemented from IlCalendar.

virtual void IlGregorianCalendar::roll ( IlDateFields  field,
IlInt  amount,
IlDateErrorCode status 
) [virtual]

Rolls up or down by the given amount in the specified field.

(Overrides IlCalendar)

Parameters:
field The time field.
amount Indicates amount to roll.
status The output param is set to success/failure code on exit. If any value previously set in the time field is invalid, it will be set to an error status.
See also:
IlCalendar::roll().

Implements IlCalendar.

void IlGregorianCalendar::setGregorianChange ( IlDate  date,
IlDateErrorCode success 
)

Sets the IlGregorianCalendar change date.

The change date is the point when the switch from Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 15, 1582. Prior to this time and date are Julian dates.

Parameters:
date The given Gregorian cutover date.
success Output param set to success/failure code on exit.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

© Copyright 2012, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.