Logo Search packages:      
Sourcecode: icu version File versions

Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends

GregorianCalendar Class Reference

#include <gregocal.h>

Inheritance diagram for GregorianCalendar:
Inheritance graph
[legend]
Collaboration diagram for GregorianCalendar:
Collaboration graph
[legend]

List of all members.

Public Types

enum  EAmpm { AM, PM }
enum  EDateFields {
  ERA, YEAR, MONTH, WEEK_OF_YEAR,
  WEEK_OF_MONTH, DATE, DAY_OF_YEAR, DAY_OF_WEEK,
  DAY_OF_WEEK_IN_MONTH, AM_PM, HOUR, HOUR_OF_DAY,
  MINUTE, SECOND, MILLISECOND, ZONE_OFFSET,
  DST_OFFSET, YEAR_WOY, DOW_LOCAL, EXTENDED_YEAR,
  JULIAN_DAY, MILLISECONDS_IN_DAY, IS_LEAP_MONTH, FIELD_COUNT = UCAL_FIELD_COUNT
}
enum  EDaysOfWeek {
  SUNDAY = 1, MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY
}
enum  EEras { BC, AD }
enum  EMonths {
  JANUARY, FEBRUARY, MARCH, APRIL,
  MAY, JUNE, JULY, AUGUST,
  SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER,
  UNDECIMBER
}

Public Member Functions

virtual void add (EDateFields field, int32_t amount, UErrorCode &status)
virtual void add (UCalendarDateFields field, int32_t amount, UErrorCode &status)
void adoptTimeZone (TimeZone *value)
UBool after (const Calendar &when, UErrorCode &status) const
UBool before (const Calendar &when, UErrorCode &status) const
void clear (void)
void clear (EDateFields field)
void clear (UCalendarDateFields field)
virtual Calendarclone (void) const
virtual UDate defaultCenturyStart () const
virtual int32_t defaultCenturyStartYear () const
UBool equals (const Calendar &when, UErrorCode &status) const
virtual int32_t fieldDifference (UDate when, UCalendarDateFields field, UErrorCode &status)
virtual int32_t fieldDifference (UDate when, EDateFields field, UErrorCode &status)
int32_t get (EDateFields field, UErrorCode &status) const
int32_t get (UCalendarDateFields field, UErrorCode &status) const
int32_t getActualMaximum (EDateFields field, UErrorCode &status) const
int32_t getActualMaximum (EDateFields field) const
virtual int32_t getActualMaximum (UCalendarDateFields field, UErrorCode &status) const
int32_t getActualMinimum (EDateFields field) const
int32_t getActualMinimum (EDateFields field, UErrorCode &status) const
int32_t getActualMinimum (UCalendarDateFields field, UErrorCode &status) const
virtual UCalendarWeekdayType getDayOfWeekType (UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
virtual UClassID getDynamicClassID (void) const
EDaysOfWeek getFirstDayOfWeek (void) const
UCalendarDaysOfWeek getFirstDayOfWeek (UErrorCode &status) const
virtual int32_t getGreatestMinimum (EDateFields field) const
virtual int32_t getGreatestMinimum (UCalendarDateFields field) const
UDate getGregorianChange (void) const
virtual int32_t getLeastMaximum (UCalendarDateFields field) const
virtual int32_t getLeastMaximum (EDateFields field) const
Locale getLocale (ULocDataLocaleType type, UErrorCode &status) const
const char * getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
virtual int32_t getMaximum (EDateFields field) const
virtual int32_t getMaximum (UCalendarDateFields field) const
uint8_t getMinimalDaysInFirstWeek (void) const
virtual int32_t getMinimum (EDateFields field) const
virtual int32_t getMinimum (UCalendarDateFields field) const
UDate getTime (UErrorCode &status) const
const TimeZonegetTimeZone (void) const
virtual const char * getType () const
virtual int32_t getWeekendTransition (UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
 GregorianCalendar (const Locale &aLocale, 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)
 GregorianCalendar (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
 GregorianCalendar (TimeZone *zoneToAdopt, UErrorCode &success)
 GregorianCalendar (const GregorianCalendar &source)
 GregorianCalendar (const TimeZone &zone, UErrorCode &success)
 GregorianCalendar (const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
 GregorianCalendar (UErrorCode &success)
 GregorianCalendar (int32_t year, int32_t month, int32_t date, UErrorCode &success)
virtual UBool haveDefaultCentury () const
virtual UBool inDaylightTime (UErrorCode &status) const
virtual UBool isEquivalentTo (const Calendar &other) const
UBool isLeapYear (int32_t year) const
UBool isLenient (void) const
UBool isSet (EDateFields field) const
UBool isSet (UCalendarDateFields field) const
virtual UBool isWeekend (UDate date, UErrorCode &status) const
virtual UBool isWeekend (void) const
UBool operator!= (const Calendar &that) const
GregorianCalendaroperator= (const GregorianCalendar &right)
virtual UBool operator== (const Calendar &that) const
TimeZoneorphanTimeZone (void)
virtual void roll (EDateFields field, int32_t amount, UErrorCode &status)
virtual void roll (UCalendarDateFields field, int32_t amount, UErrorCode &status)
void roll (UCalendarDateFields field, UBool up, UErrorCode &status)
void roll (EDateFields field, UBool up, UErrorCode &status)
void set (UCalendarDateFields field, int32_t value)
void set (int32_t year, int32_t month, int32_t date)
void set (EDateFields field, int32_t value)
void set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
void set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
void setFirstDayOfWeek (UCalendarDaysOfWeek value)
void setFirstDayOfWeek (EDaysOfWeek value)
void setGregorianChange (UDate date, UErrorCode &success)
void setLenient (UBool lenient)
void setMinimalDaysInFirstWeek (uint8_t value)
void setTime (UDate date, UErrorCode &status)
void setTimeZone (const TimeZone &zone)
virtual ~GregorianCalendar ()

Static Public Member Functions

static Calendar *U_EXPORT2 createInstance (UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const TimeZone &zone, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const Locale &aLocale, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (TimeZone *zoneToAdopt, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const TimeZone &zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static const Locale *U_EXPORT2 getAvailableLocales (int32_t &count)
static StringEnumerationgetAvailableLocales (void)
static StringEnumeration *U_EXPORT2 getKeywordValuesForLocale (const char *key, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
static UDate U_EXPORT2 getNow (void)
static UClassID U_EXPORT2 getStaticClassID (void)
static void U_EXPORT2 operator delete (void *, void *) U_NO_THROW
static void U_EXPORT2 operator delete (void *p) U_NO_THROW
static void U_EXPORT2 operator delete[] (void *p) U_NO_THROW
static void *U_EXPORT2 operator new (size_t size) U_NO_THROW
static void *U_EXPORT2 operator new (size_t, void *ptr) U_NO_THROW
static void *U_EXPORT2 operator new[] (size_t size) U_NO_THROW
static URegistryKey registerFactory (ICUServiceFactory *toAdopt, UErrorCode &status)
static UBool unregister (URegistryKey key, UErrorCode &status)

Protected Types

enum  { kResolveSTOP = -1, kResolveRemap = 32 }
enum  { kUnset = 0, kInternallySet, kMinimumUserStamp }
enum  ELimitType {
  UCAL_LIMIT_MINIMUM = 0, UCAL_LIMIT_GREATEST_MINIMUM, UCAL_LIMIT_LEAST_MAXIMUM, UCAL_LIMIT_MAXIMUM,
  UCAL_LIMIT_COUNT
}

Protected Member Functions

void complete (UErrorCode &status)
virtual void computeFields (UErrorCode &status)
void computeGregorianFields (int32_t julianDay, UErrorCode &ec)
int32_t computeJulianDay ()
int32_t computeMillisInDay ()
virtual void computeTime (UErrorCode &status)
int32_t computeZoneOffset (double millis, int32_t millisInDay, UErrorCode &ec)
virtual int32_t getDefaultDayInMonth (int32_t eyear, int32_t month)
virtual int32_t getDefaultMonthInYear (int32_t eyear)
virtual UDate getEpochDay (UErrorCode &status)
virtual const
UFieldResolutionTable * 
getFieldResolutionTable () const
int32_t getGregorianDayOfMonth () const
int32_t getGregorianDayOfYear () const
int32_t getGregorianMonth () const
int32_t getGregorianYear () const
virtual int32_t getLimit (UCalendarDateFields field, ELimitType limitType) const
int32_t getLocalDOW ()
double getTimeInMillis (UErrorCode &status) const
virtual void handleComputeFields (int32_t julianDay, UErrorCode &status)
virtual int32_t handleComputeJulianDay (UCalendarDateFields bestField)
virtual int32_t handleComputeMonthStart (int32_t eyear, int32_t month, UBool useMonth) const
virtual int32_t handleGetExtendedYear ()
virtual int32_t handleGetExtendedYearFromWeekFields (int32_t yearWoy, int32_t woy)
virtual int32_t handleGetLimit (UCalendarDateFields field, ELimitType limitType) const
virtual int32_t handleGetMonthLength (int32_t extendedYear, int32_t month) const
virtual int32_t handleGetYearLength (int32_t eyear) const
int32_t internalGet (UCalendarDateFields field) const
int32_t internalGet (UCalendarDateFields field, int32_t defaultValue) const
int32_t internalGet (EDateFields field) const
virtual int32_t internalGetEra () const
UDate internalGetTime (void) const
void internalSet (EDateFields field, int32_t value)
void internalSet (UCalendarDateFields field, int32_t value)
void internalSetTime (UDate time)
virtual int32_t monthLength (int32_t month) const
virtual int32_t monthLength (int32_t month, int32_t year) const
UCalendarDateFields newerField (UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
int32_t newestStamp (UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
void pinDayOfMonth (void)
virtual void pinField (UCalendarDateFields field, UErrorCode &status)
virtual void prepareGetActual (UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
UCalendarDateFields resolveFields (const UFieldResolutionTable *precedenceTable)
void setTimeInMillis (double millis, UErrorCode &status)
int32_t weekNumber (int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
int32_t weekNumber (int32_t dayOfPeriod, int32_t dayOfWeek)
int32_t yearLength (void) const
int32_t yearLength (int32_t year) const

Static Protected Member Functions

static uint8_t julianDayToDayOfWeek (double julian)

Protected Attributes

UBool fAreAllFieldsSet
UBool fAreFieldsSet
UBool fAreFieldsVirtuallySet
int32_t fFields [UCAL_FIELD_COUNT]
UBool fIsSet [UCAL_FIELD_COUNT]
UBool fIsTimeSet
int32_t fStamp [UCAL_FIELD_COUNT]

Static Protected Attributes

static const UFieldResolutionTable kDatePrecedence []
static const UFieldResolutionTable kDOWPrecedence []
static const UFieldResolutionTable kYearPrecedence []

Private Member Functions

int32_t aggregateStamp (int32_t stamp_a, int32_t stamp_b)
UBool boundsCheck (int32_t value, UCalendarDateFields field) const
UDate internalGetDefaultCenturyStart (void) const
int32_t internalGetDefaultCenturyStartYear (void) const
UBool validateFields (void) const

Static Private Member Functions

static double computeJulianDayOfYear (UBool isGregorian, int32_t year, UBool &isLeap)
static void initializeSystemDefaultCentury (void)
static UDate julianDayToMillis (double julian)
static double millisToJulianDay (UDate millis)

Private Attributes

int32_t fCutoverJulianDay
UDate fGregorianCutover
int32_t fGregorianCutoverJulianDay
int32_t fGregorianCutoverYear
UBool fInvertGregorian
UBool fIsGregorian
UDate fNormalizedGregorianCutover

Static Private Attributes

static const UDate fgSystemDefaultCentury = DBL_MIN
static UDate fgSystemDefaultCenturyStart = DBL_MIN
static int32_t fgSystemDefaultCenturyStartYear = -1
static const int32_t fgSystemDefaultCenturyYear = -1

Friends

class CalendarFactory
class CalendarService
class DefaultCalendarFactory

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)
     UErrorCode success = U_ZERO_ERROR;
     const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
     // if no ids were returned, something is wrong. get out.
     if (ids == 0 || ids->count(success) == 0) {
         return;
     }

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

     // create a Pacific Standard Time time zone
     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));

     // set up rules for daylight savings time
     pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
     pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);

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

     // print out a bunch of interesting things
     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;

     cout << "Current Time, with hour reset to 3" << endl;
     calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
     calendar->set(UCAL_HOUR, 3);
     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours

     if (U_FAILURE(success)) {
         cout << "An error occured. success=" << u_errorName(success) << endl;
     }

     delete ids;
     delete calendar; // also deletes pdt

ICU 2.0

Definition at line 149 of file gregocal.h.


The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index