michael@0: /* michael@0: ******************************************************************************** michael@0: * Copyright (C) 1997-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ******************************************************************************** michael@0: * michael@0: * File CALENDAR.H michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 04/22/97 aliu Expanded and corrected comments and other header michael@0: * contents. michael@0: * 05/01/97 aliu Made equals(), before(), after() arguments const. michael@0: * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and michael@0: * fAreAllFieldsSet. michael@0: * 07/27/98 stephen Sync up with JDK 1.2 michael@0: * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL michael@0: * to EDateFields michael@0: * 8/19/2002 srl Removed Javaisms michael@0: * 11/07/2003 srl Update, clean up documentation. michael@0: ******************************************************************************** michael@0: */ michael@0: michael@0: #ifndef CALENDAR_H michael@0: #define CALENDAR_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Calendar object michael@0: */ michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/locid.h" michael@0: #include "unicode/timezone.h" michael@0: #include "unicode/ucal.h" michael@0: #include "unicode/umisc.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class ICUServiceFactory; michael@0: michael@0: /** michael@0: * @internal michael@0: */ michael@0: typedef int32_t UFieldResolutionTable[12][8]; michael@0: michael@0: class BasicTimeZone; michael@0: /** michael@0: * Calendar is an abstract base class for converting between michael@0: * a UDate object and a set of integer fields such as michael@0: * YEAR, MONTH, DAY, HOUR, michael@0: * and so on. (A UDate object represents a specific instant in michael@0: * time with millisecond precision. See UDate michael@0: * for information about the UDate class.) michael@0: * michael@0: *

michael@0: * Subclasses of Calendar interpret a UDate michael@0: * according to the rules of a specific calendar system. michael@0: * The most commonly used subclass of Calendar is michael@0: * GregorianCalendar. Other subclasses could represent michael@0: * the various types of lunar calendars in use in many parts of the world. michael@0: * michael@0: *

michael@0: * NOTE: (ICU 2.6) The subclass interface should be considered unstable michael@0: * - it WILL change. michael@0: * michael@0: *

michael@0: * Like other locale-sensitive classes, Calendar provides a michael@0: * static method, createInstance, for getting a generally useful michael@0: * object of this type. Calendar's createInstance method michael@0: * returns the appropriate Calendar subclass whose michael@0: * time fields have been initialized with the current date and time: michael@0: * \htmlonly

\endhtmlonly michael@0: *
michael@0:  * Calendar *rightNow = Calendar::createInstance(errCode);
michael@0:  * 
michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: *

michael@0: * A Calendar object can produce all the time field values michael@0: * needed to implement the date-time formatting for a particular language michael@0: * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional). michael@0: * michael@0: *

michael@0: * When computing a UDate from time fields, some special circumstances michael@0: * may arise: there may be insufficient information to compute the michael@0: * UDate (such as only year and month but no day in the month), michael@0: * there may be inconsistent information (such as "Tuesday, July 15, 1996" michael@0: * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous michael@0: * because of time zone transition. michael@0: * michael@0: *

michael@0: * Insufficient information. The calendar will use default michael@0: * information to specify the missing fields. This may vary by calendar; for michael@0: * the Gregorian calendar, the default for a field is the same as that of the michael@0: * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc. michael@0: * michael@0: *

michael@0: * Inconsistent information. If fields conflict, the calendar michael@0: * will give preference to fields set more recently. For example, when michael@0: * determining the day, the calendar will look for one of the following michael@0: * combinations of fields. The most recent combination, as determined by the michael@0: * most recently set single field, will be used. michael@0: * michael@0: * \htmlonly

\endhtmlonly michael@0: *
michael@0:  * MONTH + DAY_OF_MONTH
michael@0:  * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
michael@0:  * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
michael@0:  * DAY_OF_YEAR
michael@0:  * DAY_OF_WEEK + WEEK_OF_YEAR
michael@0:  * 
michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: * For the time of day: michael@0: * michael@0: * \htmlonly
\endhtmlonly michael@0: *
michael@0:  * HOUR_OF_DAY
michael@0:  * AM_PM + HOUR
michael@0:  * 
michael@0: * \htmlonly
\endhtmlonly michael@0: * michael@0: *

michael@0: * Ambiguous Wall Clock Time. When time offset from UTC has michael@0: * changed, it produces ambiguous time slot around the transition. For example, michael@0: * many US locations observe daylight saving time. On the date switching to daylight michael@0: * saving time in US, wall clock time jumps from 1:00 AM (standard) to 2:00 AM michael@0: * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on michael@0: * the date. When the input wall time fall into this missing time slot, the ICU michael@0: * Calendar resolves the time using the UTC offset before the transition by default. michael@0: * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist), michael@0: * so the final result will be 2:30 AM daylight time. michael@0: * michael@0: *

On the date switching back to standard time, wall clock time is moved back one michael@0: * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this michael@0: * case, the ICU Calendar resolves the time using the UTC offset after the transition michael@0: * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time. michael@0: * michael@0: *

Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs michael@0: * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}. michael@0: * These methods are available in ICU 49 or later versions. michael@0: * michael@0: *

michael@0: * Note: for some non-Gregorian calendars, different michael@0: * fields may be necessary for complete disambiguation. For example, a full michael@0: * specification of the historial Arabic astronomical calendar requires year, michael@0: * month, day-of-month and day-of-week in some cases. michael@0: * michael@0: *

michael@0: * Note: There are certain possible ambiguities in michael@0: * interpretation of certain singular times, which are resolved in the michael@0: * following ways: michael@0: *

    michael@0: *
  1. 24:00:00 "belongs" to the following day. That is, michael@0: * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970 michael@0: * michael@0: *
  2. Although historically not precise, midnight also belongs to "am", michael@0: * and noon belongs to "pm", so on the same day, michael@0: * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm michael@0: *
michael@0: * michael@0: *

michael@0: * The date or time format strings are not part of the definition of a michael@0: * calendar, as those must be modifiable or overridable by the user at michael@0: * runtime. Use {@link DateFormat} michael@0: * to format dates. michael@0: * michael@0: *

michael@0: * Calendar provides an API for field "rolling", where fields michael@0: * can be incremented or decremented, but wrap around. For example, rolling the michael@0: * month up in the date December 12, 1996 results in michael@0: * January 12, 1996. michael@0: * michael@0: *

michael@0: * Calendar also provides a date arithmetic function for michael@0: * adding the specified (signed) amount of time to a particular time field. michael@0: * For example, subtracting 5 days from the date September 12, 1996 michael@0: * results in September 7, 1996. michael@0: * michael@0: *

Supported range michael@0: * michael@0: *

The allowable range of Calendar has been michael@0: * narrowed. GregorianCalendar used to attempt to support michael@0: * the range of dates with millisecond values from michael@0: * Long.MIN_VALUE to Long.MAX_VALUE. michael@0: * The new Calendar protocol specifies the michael@0: * maximum range of supportable dates as those having Julian day numbers michael@0: * of -0x7F000000 to +0x7F000000. This michael@0: * corresponds to years from ~5,800,000 BCE to ~5,800,000 CE. Programmers michael@0: * should use the protected constants in Calendar to michael@0: * specify an extremely early or extremely late date.

michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: class U_I18N_API Calendar : public UObject { michael@0: public: michael@0: michael@0: /** michael@0: * Field IDs for date and time. Used to specify date/time fields. ERA is calendar michael@0: * specific. Example ranges given are for illustration only; see specific Calendar michael@0: * subclasses for actual ranges. michael@0: * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h michael@0: */ michael@0: enum EDateFields { michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /* michael@0: * ERA may be defined on other platforms. To avoid any potential problems undefined it here. michael@0: */ michael@0: #ifdef ERA michael@0: #undef ERA michael@0: #endif michael@0: ERA, // Example: 0..1 michael@0: YEAR, // Example: 1..big number michael@0: MONTH, // Example: 0..11 michael@0: WEEK_OF_YEAR, // Example: 1..53 michael@0: WEEK_OF_MONTH, // Example: 1..4 michael@0: DATE, // Example: 1..31 michael@0: DAY_OF_YEAR, // Example: 1..365 michael@0: DAY_OF_WEEK, // Example: 1..7 michael@0: DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1 michael@0: AM_PM, // Example: 0..1 michael@0: HOUR, // Example: 0..11 michael@0: HOUR_OF_DAY, // Example: 0..23 michael@0: MINUTE, // Example: 0..59 michael@0: SECOND, // Example: 0..59 michael@0: MILLISECOND, // Example: 0..999 michael@0: ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR michael@0: DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR michael@0: YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year michael@0: DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized michael@0: michael@0: EXTENDED_YEAR, michael@0: JULIAN_DAY, michael@0: MILLISECONDS_IN_DAY, michael@0: IS_LEAP_MONTH, michael@0: michael@0: FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields. michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: }; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients michael@0: * who create locale resources for the field of first-day-of-week should be aware of michael@0: * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY. michael@0: * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h michael@0: */ michael@0: enum EDaysOfWeek { michael@0: SUNDAY = 1, michael@0: MONDAY, michael@0: TUESDAY, michael@0: WEDNESDAY, michael@0: THURSDAY, michael@0: FRIDAY, michael@0: SATURDAY michael@0: }; michael@0: michael@0: /** michael@0: * Useful constants for month. Note: Calendar month is 0-based. michael@0: * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h michael@0: */ michael@0: enum EMonths { michael@0: JANUARY, michael@0: FEBRUARY, michael@0: MARCH, michael@0: APRIL, michael@0: MAY, michael@0: JUNE, michael@0: JULY, michael@0: AUGUST, michael@0: SEPTEMBER, michael@0: OCTOBER, michael@0: NOVEMBER, michael@0: DECEMBER, michael@0: UNDECIMBER michael@0: }; michael@0: michael@0: /** michael@0: * Useful constants for hour in 12-hour clock. Used in GregorianCalendar. michael@0: * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h michael@0: */ michael@0: enum EAmpm { michael@0: AM, michael@0: PM michael@0: }; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * destructor michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~Calendar(); michael@0: michael@0: /** michael@0: * Create and return a polymorphic copy of this calendar. michael@0: * michael@0: * @return a polymorphic copy of this calendar. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual Calendar* clone(void) const = 0; michael@0: michael@0: /** michael@0: * Creates a Calendar using the default timezone and locale. Clients are responsible michael@0: * for deleting the object returned. michael@0: * michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data michael@0: * requests a calendar type which has not been installed. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(UErrorCode& success); michael@0: michael@0: /** michael@0: * Creates a Calendar using the given timezone and the default locale. michael@0: * The Calendar takes ownership of zoneToAdopt; the michael@0: * client must not delete it. michael@0: * michael@0: * @param zoneToAdopt The given timezone to be adopted. michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success); michael@0: michael@0: /** michael@0: * Creates a Calendar using the given timezone and the default locale. The TimeZone michael@0: * is _not_ adopted; the client is still responsible for deleting it. michael@0: * michael@0: * @param zone The timezone. michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success); michael@0: michael@0: /** michael@0: * Creates a Calendar using the default timezone and the given locale. michael@0: * michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success); michael@0: michael@0: /** michael@0: * Creates a Calendar using the given timezone and given locale. michael@0: * The Calendar takes ownership of zoneToAdopt; the michael@0: * client must not delete it. michael@0: * michael@0: * @param zoneToAdopt The given timezone to be adopted. michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success); michael@0: michael@0: /** michael@0: * Gets a Calendar using the given timezone and given locale. The TimeZone michael@0: * is _not_ adopted; the client is still responsible for deleting it. michael@0: * michael@0: * @param zone The given timezone. michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the success/failure of Calendar creation. Filled in michael@0: * with U_ZERO_ERROR if created successfully, set to a failure result michael@0: * otherwise. michael@0: * @return A Calendar if created successfully. NULL otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success); michael@0: michael@0: /** michael@0: * Returns a list of the locales for which Calendars are installed. michael@0: * michael@0: * @param count Number of locales returned. michael@0: * @return An array of Locale objects representing the set of locales for which michael@0: * Calendars are installed. The system retains ownership of this list; michael@0: * the caller must NOT delete it. Does not include user-registered Calendars. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count); michael@0: michael@0: michael@0: /** michael@0: * Given a key and a locale, returns an array of string values in a preferred michael@0: * order that would make a difference. These are all and only those values where michael@0: * the open (creation) of the service with the locale formed from the input locale michael@0: * plus input keyword and that value has different behavior than creation with the michael@0: * input locale alone. michael@0: * @param key one of the keys supported by this service. For now, only michael@0: * "calendar" is supported. michael@0: * @param locale the locale michael@0: * @param commonlyUsed if set to true it will return only commonly used values michael@0: * with the given locale in preferred order. Otherwise, michael@0: * it will return all the available values for the locale. michael@0: * @param status ICU Error Code michael@0: * @return a string enumeration over keyword values for the given key and the locale. michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key, michael@0: const Locale& locale, UBool commonlyUsed, UErrorCode& status); michael@0: michael@0: /** michael@0: * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 michael@0: * (derived from the system time). michael@0: * michael@0: * @return The current UTC time in milliseconds. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: static UDate U_EXPORT2 getNow(void); michael@0: michael@0: /** michael@0: * Gets this Calendar's time as milliseconds. May involve recalculation of time due michael@0: * to previous calls to set time field values. The time specified is non-local UTC michael@0: * (GMT) time. Although this method is const, this object may actually be changed michael@0: * (semantically const). michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @return The current time in UTC (GMT) time, or zero if the operation michael@0: * failed. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); } michael@0: michael@0: /** michael@0: * Sets this Calendar's current time with the given UDate. The time specified should michael@0: * be in non-local UTC (GMT) time. michael@0: * michael@0: * @param date The given UDate in UTC (GMT) time. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); } michael@0: michael@0: /** michael@0: * Compares the equality of two Calendar objects. Objects of different subclasses michael@0: * are considered unequal. This comparison is very exacting; two Calendar objects michael@0: * must be in exactly the same state to be considered equal. To compare based on the michael@0: * represented time, use equals() instead. michael@0: * michael@0: * @param that The Calendar object to be compared with. michael@0: * @return True if the given Calendar is the same as this Calendar; false michael@0: * otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool operator==(const Calendar& that) const; michael@0: michael@0: /** michael@0: * Compares the inequality of two Calendar objects. michael@0: * michael@0: * @param that The Calendar object to be compared with. michael@0: * @return True if the given Calendar is not the same as this Calendar; false michael@0: * otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool operator!=(const Calendar& that) const {return !operator==(that);} michael@0: michael@0: /** michael@0: * Returns TRUE if the given Calendar object is equivalent to this michael@0: * one. An equivalent Calendar will behave exactly as this one michael@0: * does, but it may be set to a different time. By contrast, for michael@0: * the operator==() method to return TRUE, the other Calendar must michael@0: * be set to the same time. michael@0: * michael@0: * @param other the Calendar to be compared with this Calendar michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UBool isEquivalentTo(const Calendar& other) const; michael@0: michael@0: /** michael@0: * Compares the Calendar time, whereas Calendar::operator== compares the equality of michael@0: * Calendar objects. michael@0: * michael@0: * @param when The Calendar to be compared with this Calendar. Although this is a michael@0: * const parameter, the object may be modified physically michael@0: * (semantically const). michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @return True if the current time of this Calendar is equal to the time of michael@0: * Calendar when; false otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool equals(const Calendar& when, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Returns true if this Calendar's current time is before "when"'s current time. michael@0: * michael@0: * @param when The Calendar to be compared with this Calendar. Although this is a michael@0: * const parameter, the object may be modified physically michael@0: * (semantically const). michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @return True if the current time of this Calendar is before the time of michael@0: * Calendar when; false otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool before(const Calendar& when, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Returns true if this Calendar's current time is after "when"'s current time. michael@0: * michael@0: * @param when The Calendar to be compared with this Calendar. Although this is a michael@0: * const parameter, the object may be modified physically michael@0: * (semantically const). michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @return True if the current time of this Calendar is after the time of michael@0: * Calendar when; false otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool after(const Calendar& when, UErrorCode& status) const; michael@0: michael@0: /** michael@0: * UDate Arithmetic function. Adds the specified (signed) amount of time to the given michael@0: * time field, based on the calendar's rules. For example, to subtract 5 days from michael@0: * the current time of the calendar, call add(Calendar::DATE, -5). When adding on michael@0: * the month or Calendar::MONTH field, other fields like date might conflict and michael@0: * need to be changed. For instance, adding 1 month on the date 01/31/96 will result michael@0: * in 02/29/96. michael@0: * Adding a positive value always means moving forward in time, so for the Gregorian calendar, michael@0: * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces michael@0: * the numeric value of the field itself). michael@0: * michael@0: * @param field Specifies which date field to modify. michael@0: * @param amount The amount of time to be added to the field, in the natural unit michael@0: * for that field (e.g., days for the day fields, hours for the hour michael@0: * field.) michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead. michael@0: */ michael@0: virtual void add(EDateFields field, int32_t amount, UErrorCode& status); michael@0: michael@0: /** michael@0: * UDate Arithmetic function. Adds the specified (signed) amount of time to the given michael@0: * time field, based on the calendar's rules. For example, to subtract 5 days from michael@0: * the current time of the calendar, call add(Calendar::DATE, -5). When adding on michael@0: * the month or Calendar::MONTH field, other fields like date might conflict and michael@0: * need to be changed. For instance, adding 1 month on the date 01/31/96 will result michael@0: * in 02/29/96. michael@0: * Adding a positive value always means moving forward in time, so for the Gregorian calendar, michael@0: * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces michael@0: * the numeric value of the field itself). michael@0: * michael@0: * @param field Specifies which date field to modify. michael@0: * @param amount The amount of time to be added to the field, in the natural unit michael@0: * for that field (e.g., days for the day fields, hours for the hour michael@0: * field.) michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status); michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Time Field Rolling function. Rolls (up/down) a single unit of time on the given michael@0: * time field. For example, to roll the current date up by one day, call michael@0: * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it michael@0: * will roll the year value in the range between getMinimum(Calendar::YEAR) and the michael@0: * value returned by getMaximum(Calendar::YEAR). When rolling on the month or michael@0: * Calendar::MONTH field, other fields like date might conflict and, need to be michael@0: * changed. For instance, rolling the month up on the date 01/31/96 will result in michael@0: * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the michael@0: * field is reached, in which case it may pin or wrap), so for Gregorian calendar, michael@0: * starting with 100 BC and rolling the year up results in 99 BC. michael@0: * When eras have a definite beginning and end (as in the Chinese calendar, or as in michael@0: * most eras in the Japanese calendar) then rolling the year past either limit of the michael@0: * era will cause the year to wrap around. When eras only have a limit at one end, michael@0: * then attempting to roll the year past that limit will result in pinning the year michael@0: * at that limit. Note that for most calendars in which era 0 years move forward in michael@0: * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to michael@0: * result in negative years for era 0 (that is the only way to represent years before michael@0: * the calendar epoch). michael@0: * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the michael@0: * hour value in the range between 0 and 23, which is zero-based. michael@0: *

michael@0: * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead. michael@0: * michael@0: * @param field The time field. michael@0: * @param up Indicates if the value of the specified time field is to be rolled michael@0: * up or rolled down. Use true if rolling up, false otherwise. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead. michael@0: */ michael@0: inline void roll(EDateFields field, UBool up, UErrorCode& status); michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Time Field Rolling function. Rolls (up/down) a single unit of time on the given michael@0: * time field. For example, to roll the current date up by one day, call michael@0: * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it michael@0: * will roll the year value in the range between getMinimum(Calendar::YEAR) and the michael@0: * value returned by getMaximum(Calendar::YEAR). When rolling on the month or michael@0: * Calendar::MONTH field, other fields like date might conflict and, need to be michael@0: * changed. For instance, rolling the month up on the date 01/31/96 will result in michael@0: * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the michael@0: * field is reached, in which case it may pin or wrap), so for Gregorian calendar, michael@0: * starting with 100 BC and rolling the year up results in 99 BC. michael@0: * When eras have a definite beginning and end (as in the Chinese calendar, or as in michael@0: * most eras in the Japanese calendar) then rolling the year past either limit of the michael@0: * era will cause the year to wrap around. When eras only have a limit at one end, michael@0: * then attempting to roll the year past that limit will result in pinning the year michael@0: * at that limit. Note that for most calendars in which era 0 years move forward in michael@0: * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to michael@0: * result in negative years for era 0 (that is the only way to represent years before michael@0: * the calendar epoch). michael@0: * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the michael@0: * hour value in the range between 0 and 23, which is zero-based. michael@0: *

michael@0: * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead. michael@0: * michael@0: * @param field The time field. michael@0: * @param up Indicates if the value of the specified time field is to be rolled michael@0: * up or rolled down. Use true if rolling up, false otherwise. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status); michael@0: michael@0: /** michael@0: * Time Field Rolling function. Rolls by the given amount on the given michael@0: * time field. For example, to roll the current date up by one day, call michael@0: * roll(Calendar::DATE, +1, status). When rolling on the month or michael@0: * Calendar::MONTH field, other fields like date might conflict and, need to be michael@0: * changed. For instance, rolling the month up on the date 01/31/96 will result in michael@0: * 02/29/96. Rolling by a positive value always means rolling forward in time (unless michael@0: * the limit of the field is reached, in which case it may pin or wrap), so for michael@0: * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC. michael@0: * When eras have a definite beginning and end (as in the Chinese calendar, or as in michael@0: * most eras in the Japanese calendar) then rolling the year past either limit of the michael@0: * era will cause the year to wrap around. When eras only have a limit at one end, michael@0: * then attempting to roll the year past that limit will result in pinning the year michael@0: * at that limit. Note that for most calendars in which era 0 years move forward in michael@0: * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to michael@0: * result in negative years for era 0 (that is the only way to represent years before michael@0: * the calendar epoch). michael@0: * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the michael@0: * hour value in the range between 0 and 23, which is zero-based. michael@0: *

michael@0: * The only difference between roll() and add() is that roll() does not change michael@0: * the value of more significant fields when it reaches the minimum or maximum michael@0: * of its range, whereas add() does. michael@0: * michael@0: * @param field The time field. michael@0: * @param amount Indicates amount to roll. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid, this will be set to michael@0: * an error status. michael@0: * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead. michael@0: */ michael@0: virtual void roll(EDateFields field, int32_t amount, UErrorCode& status); michael@0: michael@0: /** michael@0: * Time Field Rolling function. Rolls by the given amount on the given michael@0: * time field. For example, to roll the current date up by one day, call michael@0: * roll(Calendar::DATE, +1, status). When rolling on the month or michael@0: * Calendar::MONTH field, other fields like date might conflict and, need to be michael@0: * changed. For instance, rolling the month up on the date 01/31/96 will result in michael@0: * 02/29/96. Rolling by a positive value always means rolling forward in time (unless michael@0: * the limit of the field is reached, in which case it may pin or wrap), so for michael@0: * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC. michael@0: * When eras have a definite beginning and end (as in the Chinese calendar, or as in michael@0: * most eras in the Japanese calendar) then rolling the year past either limit of the michael@0: * era will cause the year to wrap around. When eras only have a limit at one end, michael@0: * then attempting to roll the year past that limit will result in pinning the year michael@0: * at that limit. Note that for most calendars in which era 0 years move forward in michael@0: * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to michael@0: * result in negative years for era 0 (that is the only way to represent years before michael@0: * the calendar epoch). michael@0: * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the michael@0: * hour value in the range between 0 and 23, which is zero-based. michael@0: *

michael@0: * The only difference between roll() and add() is that roll() does not change michael@0: * the value of more significant fields when it reaches the minimum or maximum michael@0: * of its range, whereas add() does. michael@0: * michael@0: * @param field The time field. michael@0: * @param amount Indicates amount to roll. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid, this will be set to michael@0: * an error status. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status); michael@0: michael@0: /** michael@0: * Return the difference between the given time and the time this michael@0: * calendar object is set to. If this calendar is set michael@0: * before the given time, the returned value will be michael@0: * positive. If this calendar is set after the given michael@0: * time, the returned value will be negative. The michael@0: * field parameter specifies the units of the return michael@0: * value. For example, if fieldDifference(when, michael@0: * Calendar::MONTH) returns 3, then this calendar is set to michael@0: * 3 months before when, and possibly some addition michael@0: * time less than one month. michael@0: * michael@0: *

As a side effect of this call, this calendar is advanced michael@0: * toward when by the given amount. That is, calling michael@0: * this method has the side effect of calling add(field, michael@0: * n), where n is the return value. michael@0: * michael@0: *

Usage: To use this method, call it first with the largest michael@0: * field of interest, then with progressively smaller fields. For michael@0: * example: michael@0: * michael@0: *

michael@0:      * int y = cal->fieldDifference(when, Calendar::YEAR, err);
michael@0:      * int m = cal->fieldDifference(when, Calendar::MONTH, err);
michael@0:      * int d = cal->fieldDifference(when, Calendar::DATE, err);
michael@0: * michael@0: * computes the difference between cal and michael@0: * when in years, months, and days. michael@0: * michael@0: *

Note: fieldDifference() is michael@0: * asymmetrical. That is, in the following code: michael@0: * michael@0: *

michael@0:      * cal->setTime(date1, err);
michael@0:      * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
michael@0:      * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
michael@0:      * cal->setTime(date2, err);
michael@0:      * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
michael@0:      * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);
michael@0: * michael@0: * one might expect that m1 == -m2 && d1 == -d2. michael@0: * However, this is not generally the case, because of michael@0: * irregularities in the underlying calendar system (e.g., the michael@0: * Gregorian calendar has a varying number of days per month). michael@0: * michael@0: * @param when the date to compare this calendar's time to michael@0: * @param field the field in which to compute the result michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid, this will be set to michael@0: * an error status. michael@0: * @return the difference, either positive or negative, between michael@0: * this calendar's time and when, in terms of michael@0: * field. michael@0: * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status). michael@0: */ michael@0: virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status); michael@0: michael@0: /** michael@0: * Return the difference between the given time and the time this michael@0: * calendar object is set to. If this calendar is set michael@0: * before the given time, the returned value will be michael@0: * positive. If this calendar is set after the given michael@0: * time, the returned value will be negative. The michael@0: * field parameter specifies the units of the return michael@0: * value. For example, if fieldDifference(when, michael@0: * Calendar::MONTH) returns 3, then this calendar is set to michael@0: * 3 months before when, and possibly some addition michael@0: * time less than one month. michael@0: * michael@0: *

As a side effect of this call, this calendar is advanced michael@0: * toward when by the given amount. That is, calling michael@0: * this method has the side effect of calling add(field, michael@0: * n), where n is the return value. michael@0: * michael@0: *

Usage: To use this method, call it first with the largest michael@0: * field of interest, then with progressively smaller fields. For michael@0: * example: michael@0: * michael@0: *

michael@0:      * int y = cal->fieldDifference(when, Calendar::YEAR, err);
michael@0:      * int m = cal->fieldDifference(when, Calendar::MONTH, err);
michael@0:      * int d = cal->fieldDifference(when, Calendar::DATE, err);
michael@0: * michael@0: * computes the difference between cal and michael@0: * when in years, months, and days. michael@0: * michael@0: *

Note: fieldDifference() is michael@0: * asymmetrical. That is, in the following code: michael@0: * michael@0: *

michael@0:      * cal->setTime(date1, err);
michael@0:      * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
michael@0:      * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
michael@0:      * cal->setTime(date2, err);
michael@0:      * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
michael@0:      * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);
michael@0: * michael@0: * one might expect that m1 == -m2 && d1 == -d2. michael@0: * However, this is not generally the case, because of michael@0: * irregularities in the underlying calendar system (e.g., the michael@0: * Gregorian calendar has a varying number of days per month). michael@0: * michael@0: * @param when the date to compare this calendar's time to michael@0: * @param field the field in which to compute the result michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid, this will be set to michael@0: * an error status. michael@0: * @return the difference, either positive or negative, between michael@0: * this calendar's time and when, in terms of michael@0: * field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status); michael@0: michael@0: /** michael@0: * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership michael@0: * of the TimeZone; the caller is no longer responsible for deleting it. If the michael@0: * given time zone is NULL, this function has no effect. michael@0: * michael@0: * @param value The given time zone. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void adoptTimeZone(TimeZone* value); michael@0: michael@0: /** michael@0: * Sets the calendar's time zone to be the same as the one passed in. The TimeZone michael@0: * passed in is _not_ adopted; the client is still responsible for deleting it. michael@0: * michael@0: * @param zone The given time zone. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setTimeZone(const TimeZone& zone); michael@0: michael@0: /** michael@0: * Returns a reference to the time zone owned by this calendar. The returned reference michael@0: * is only valid until clients make another call to adoptTimeZone or setTimeZone, michael@0: * or this Calendar is destroyed. michael@0: * michael@0: * @return The time zone object associated with this calendar. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: const TimeZone& getTimeZone(void) const; michael@0: michael@0: /** michael@0: * Returns the time zone owned by this calendar. The caller owns the returned object michael@0: * and must delete it when done. After this call, the new time zone associated michael@0: * with this Calendar is the default TimeZone as returned by TimeZone::createDefault(). michael@0: * michael@0: * @return The time zone object which was associated with this calendar. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: TimeZone* orphanTimeZone(void); michael@0: michael@0: /** michael@0: * Queries if the current date for this Calendar is in Daylight Savings Time. michael@0: * michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return True if the current date for this Calendar is in Daylight Savings Time, michael@0: * false, otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UBool inDaylightTime(UErrorCode& status) const = 0; michael@0: michael@0: /** michael@0: * Specifies whether or not date/time interpretation is to be lenient. With lenient michael@0: * interpretation, a date such as "February 942, 1996" will be treated as being michael@0: * equivalent to the 941st day after February 1, 1996. With strict interpretation, michael@0: * such dates will cause an error when computing time from the time field values michael@0: * representing the dates. michael@0: * michael@0: * @param lenient True specifies date/time interpretation to be lenient. michael@0: * michael@0: * @see DateFormat#setLenient michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setLenient(UBool lenient); michael@0: michael@0: /** michael@0: * Tells whether date/time interpretation is to be lenient. michael@0: * michael@0: * @return True tells that date/time interpretation is to be lenient. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool isLenient(void) const; michael@0: michael@0: /** michael@0: * Sets the behavior for handling wall time repeating multiple times michael@0: * at negative time zone offset transitions. For example, 1:30 AM on michael@0: * November 6, 2011 in US Eastern time (Ameirca/New_York) occurs twice; michael@0: * 1:30 AM EDT, then 1:30 AM EST one hour later. When UCAL_WALLTIME_FIRST michael@0: * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT michael@0: * (first occurrence). When UCAL_WALLTIME_LAST is used, it will be michael@0: * interpreted as 1:30 AM EST (last occurrence). The default value is michael@0: * UCAL_WALLTIME_LAST. michael@0: *

michael@0: * Note:When UCAL_WALLTIME_NEXT_VALID is not a valid michael@0: * option for this. When the argument is neither UCAL_WALLTIME_FIRST michael@0: * nor UCAL_WALLTIME_LAST, this method has no effect and will keep michael@0: * the current setting. michael@0: * michael@0: * @param option the behavior for handling repeating wall time, either michael@0: * UCAL_WALLTIME_FIRST or UCAL_WALLTIME_LAST. michael@0: * @see #getRepeatedWallTimeOption michael@0: * @stable ICU 49 michael@0: */ michael@0: void setRepeatedWallTimeOption(UCalendarWallTimeOption option); michael@0: michael@0: /** michael@0: * Gets the behavior for handling wall time repeating multiple times michael@0: * at negative time zone offset transitions. michael@0: * michael@0: * @return the behavior for handling repeating wall time, either michael@0: * UCAL_WALLTIME_FIRST or UCAL_WALLTIME_LAST. michael@0: * @see #setRepeatedWallTimeOption michael@0: * @stable ICU 49 michael@0: */ michael@0: UCalendarWallTimeOption getRepeatedWallTimeOption(void) const; michael@0: michael@0: /** michael@0: * Sets the behavior for handling skipped wall time at positive time zone offset michael@0: * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York) michael@0: * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When michael@0: * UCAL_WALLTIME_FIRST is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM michael@0: * EDT, therefore, it will be resolved as 1:30 AM EST. When UCAL_WALLTIME_LAST michael@0: * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be michael@0: * resolved as 3:30 AM EDT. When UCAL_WALLTIME_NEXT_VALID is used, 2:30 AM will michael@0: * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is michael@0: * UCAL_WALLTIME_LAST. michael@0: *

michael@0: * Note:This option is effective only when this calendar is lenient. michael@0: * When the calendar is strict, such non-existing wall time will cause an error. michael@0: * michael@0: * @param option the behavior for handling skipped wall time at positive time zone michael@0: * offset transitions, one of UCAL_WALLTIME_FIRST, UCAL_WALLTIME_LAST and michael@0: * UCAL_WALLTIME_NEXT_VALID. michael@0: * @see #getSkippedWallTimeOption michael@0: * michael@0: * @stable ICU 49 michael@0: */ michael@0: void setSkippedWallTimeOption(UCalendarWallTimeOption option); michael@0: michael@0: /** michael@0: * Gets the behavior for handling skipped wall time at positive time zone offset michael@0: * transitions. michael@0: * michael@0: * @return the behavior for handling skipped wall time, one of michael@0: * UCAL_WALLTIME_FIRST, UCAL_WALLTIME_LAST michael@0: * and UCAL_WALLTIME_NEXT_VALID. michael@0: * @see #setSkippedWallTimeOption michael@0: * @stable ICU 49 michael@0: */ michael@0: UCalendarWallTimeOption getSkippedWallTimeOption(void) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Sets what the first day of the week is; e.g., Sunday in US, Monday in France. michael@0: * michael@0: * @param value The given first day of the week. michael@0: * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead. michael@0: */ michael@0: void setFirstDayOfWeek(EDaysOfWeek value); michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Sets what the first day of the week is; e.g., Sunday in US, Monday in France. michael@0: * michael@0: * @param value The given first day of the week. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: void setFirstDayOfWeek(UCalendarDaysOfWeek value); michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Gets what the first day of the week is; e.g., Sunday in US, Monday in France. michael@0: * michael@0: * @return The first day of the week. michael@0: * @deprecated ICU 2.6 use the overload with error code michael@0: */ michael@0: EDaysOfWeek getFirstDayOfWeek(void) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Gets what the first day of the week is; e.g., Sunday in US, Monday in France. michael@0: * michael@0: * @param status error code michael@0: * @return The first day of the week. michael@0: * @stable ICU 2.6 michael@0: */ michael@0: UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Sets what the minimal days required in the first week of the year are; For michael@0: * example, if the first week is defined as one that contains the first day of the michael@0: * first month of a year, call the method with value 1. If it must be a full week, michael@0: * use value 7. michael@0: * michael@0: * @param value The given minimal days required in the first week of the year. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setMinimalDaysInFirstWeek(uint8_t value); michael@0: michael@0: /** michael@0: * Gets what the minimal days required in the first week of the year are; e.g., if michael@0: * the first week is defined as one that contains the first day of the first month michael@0: * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must michael@0: * be a full week, getMinimalDaysInFirstWeek returns 7. michael@0: * michael@0: * @return The minimal days required in the first week of the year. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: uint8_t getMinimalDaysInFirstWeek(void) const; michael@0: michael@0: /** michael@0: * Gets the minimum value for the given time field. e.g., for Gregorian michael@0: * DAY_OF_MONTH, 1. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The minimum value for the given time field. michael@0: * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead. michael@0: */ michael@0: virtual int32_t getMinimum(EDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the minimum value for the given time field. e.g., for Gregorian michael@0: * DAY_OF_MONTH, 1. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The minimum value for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getMinimum(UCalendarDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH, michael@0: * 31. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The maximum value for the given time field. michael@0: * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead. michael@0: */ michael@0: virtual int32_t getMaximum(EDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH, michael@0: * 31. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The maximum value for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getMaximum(UCalendarDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the highest minimum value for the given field if varies. Otherwise same as michael@0: * getMinimum(). For Gregorian, no difference. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The highest minimum value for the given time field. michael@0: * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead. michael@0: */ michael@0: virtual int32_t getGreatestMinimum(EDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the highest minimum value for the given field if varies. Otherwise same as michael@0: * getMinimum(). For Gregorian, no difference. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The highest minimum value for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getGreatestMinimum(UCalendarDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the lowest maximum value for the given field if varies. Otherwise same as michael@0: * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The lowest maximum value for the given time field. michael@0: * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead. michael@0: */ michael@0: virtual int32_t getLeastMaximum(EDateFields field) const; michael@0: michael@0: /** michael@0: * Gets the lowest maximum value for the given field if varies. Otherwise same as michael@0: * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The lowest maximum value for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getLeastMaximum(UCalendarDateFields field) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Return the minimum value that this field could have, given the current date. michael@0: * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum(). michael@0: * michael@0: * The version of this function on Calendar uses an iterative algorithm to determine the michael@0: * actual minimum value for the field. There is almost always a more efficient way to michael@0: * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar michael@0: * overrides this function with a more efficient implementation. michael@0: * michael@0: * @param field the field to determine the minimum of michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return the minimum of the given field for the current date of this Calendar michael@0: * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead. michael@0: */ michael@0: int32_t getActualMinimum(EDateFields field, UErrorCode& status) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Return the minimum value that this field could have, given the current date. michael@0: * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum(). michael@0: * michael@0: * The version of this function on Calendar uses an iterative algorithm to determine the michael@0: * actual minimum value for the field. There is almost always a more efficient way to michael@0: * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar michael@0: * overrides this function with a more efficient implementation. michael@0: * michael@0: * @param field the field to determine the minimum of michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return the minimum of the given field for the current date of this Calendar michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Return the maximum value that this field could have, given the current date. michael@0: * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual michael@0: * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, michael@0: * for some years the actual maximum for MONTH is 12, and for others 13. michael@0: * michael@0: * The version of this function on Calendar uses an iterative algorithm to determine the michael@0: * actual maximum value for the field. There is almost always a more efficient way to michael@0: * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar michael@0: * overrides this function with a more efficient implementation. michael@0: * michael@0: * @param field the field to determine the maximum of michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return the maximum of the given field for the current date of this Calendar michael@0: * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field, UErrorCode& status) instead. michael@0: */ michael@0: int32_t getActualMaximum(EDateFields field, UErrorCode& status) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Return the maximum value that this field could have, given the current date. michael@0: * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual michael@0: * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, michael@0: * for some years the actual maximum for MONTH is 12, and for others 13. michael@0: * michael@0: * The version of this function on Calendar uses an iterative algorithm to determine the michael@0: * actual maximum value for the field. There is almost always a more efficient way to michael@0: * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar michael@0: * overrides this function with a more efficient implementation. michael@0: * michael@0: * @param field the field to determine the maximum of michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return the maximum of the given field for the current date of this Calendar michael@0: * @stable ICU 2.6. michael@0: */ michael@0: virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Gets the value for a given time field. Recalculate the current time field values michael@0: * if the time value has been changed by a call to setTime(). Return zero for unset michael@0: * fields if any fields have been explicitly set by a call to set(). To force a michael@0: * recomputation of all fields regardless of the previous state, call complete(). michael@0: * This method is semantically const, but may alter the object in memory. michael@0: * michael@0: * @param field The given time field. michael@0: * @param status Fill-in parameter which receives the status of the operation. michael@0: * @return The value for the given time field, or zero if the field is unset, michael@0: * and set() has been called for any other field. michael@0: * @deprecated ICU 2.6. Use get(UCalendarDateFields field, UErrorCode& status) instead. michael@0: */ michael@0: int32_t get(EDateFields field, UErrorCode& status) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Gets the value for a given time field. Recalculate the current time field values michael@0: * if the time value has been changed by a call to setTime(). Return zero for unset michael@0: * fields if any fields have been explicitly set by a call to set(). To force a michael@0: * recomputation of all fields regardless of the previous state, call complete(). michael@0: * This method is semantically const, but may alter the object in memory. michael@0: * michael@0: * @param field The given time field. michael@0: * @param status Fill-in parameter which receives the status of the operation. michael@0: * @return The value for the given time field, or zero if the field is unset, michael@0: * and set() has been called for any other field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: int32_t get(UCalendarDateFields field, UErrorCode& status) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Determines if the given time field has a value set. This can affect in the michael@0: * resolving of time in Calendar. Unset fields have a value of zero, by definition. michael@0: * michael@0: * @param field The given time field. michael@0: * @return True if the given time field has a value set; false otherwise. michael@0: * @deprecated ICU 2.6. Use isSet(UCalendarDateFields field) instead. michael@0: */ michael@0: UBool isSet(EDateFields field) const; michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Determines if the given time field has a value set. This can affect in the michael@0: * resolving of time in Calendar. Unset fields have a value of zero, by definition. michael@0: * michael@0: * @param field The given time field. michael@0: * @return True if the given time field has a value set; false otherwise. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: UBool isSet(UCalendarDateFields field) const; michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Sets the given time field with the given value. michael@0: * michael@0: * @param field The given time field. michael@0: * @param value The value to be set for the given time field. michael@0: * @deprecated ICU 2.6. Use set(UCalendarDateFields field, int32_t value) instead. michael@0: */ michael@0: void set(EDateFields field, int32_t value); michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Sets the given time field with the given value. michael@0: * michael@0: * @param field The given time field. michael@0: * @param value The value to be set for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: void set(UCalendarDateFields field, int32_t value); michael@0: michael@0: /** michael@0: * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are michael@0: * retained; call clear() first if this is not desired. michael@0: * michael@0: * @param year The value used to set the YEAR time field. michael@0: * @param month The value used to set the MONTH time field. Month value is 0-based. michael@0: * e.g., 0 for January. michael@0: * @param date The value used to set the DATE time field. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void set(int32_t year, int32_t month, int32_t date); michael@0: michael@0: /** michael@0: * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other michael@0: * field values are retained; call clear() first if this is not desired. michael@0: * michael@0: * @param year The value used to set the YEAR time field. michael@0: * @param month The value used to set the MONTH time field. Month value is michael@0: * 0-based. E.g., 0 for January. michael@0: * @param date The value used to set the DATE time field. michael@0: * @param hour The value used to set the HOUR_OF_DAY time field. michael@0: * @param minute The value used to set the MINUTE time field. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute); michael@0: michael@0: /** michael@0: * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND. michael@0: * Other field values are retained; call clear() first if this is not desired. michael@0: * michael@0: * @param year The value used to set the YEAR time field. michael@0: * @param month The value used to set the MONTH time field. Month value is michael@0: * 0-based. E.g., 0 for January. michael@0: * @param date The value used to set the DATE time field. michael@0: * @param hour The value used to set the HOUR_OF_DAY time field. michael@0: * @param minute The value used to set the MINUTE time field. michael@0: * @param second The value used to set the SECOND time field. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second); michael@0: michael@0: /** michael@0: * Clears the values of all the time fields, making them both unset and assigning michael@0: * them a value of zero. The field values will be determined during the next michael@0: * resolving of time into time fields. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void clear(void); michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Clears the value in the given time field, both making it unset and assigning it a michael@0: * value of zero. This field value will be determined during the next resolving of michael@0: * time into time fields. michael@0: * michael@0: * @param field The time field to be cleared. michael@0: * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead. michael@0: */ michael@0: void clear(EDateFields field); michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Clears the value in the given time field, both making it unset and assigning it a michael@0: * value of zero. This field value will be determined during the next resolving of michael@0: * time into time fields. michael@0: * michael@0: * @param field The time field to be cleared. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: void clear(UCalendarDateFields field); michael@0: michael@0: /** michael@0: * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to michael@0: * implement a simple version of RTTI, since not all C++ compilers support genuine michael@0: * RTTI. Polymorphic operator==() and clone() methods call this method. michael@0: *

michael@0: * Concrete subclasses of Calendar must implement getDynamicClassID() and also a michael@0: * static method and data member: michael@0: * michael@0: * static UClassID getStaticClassID() { return (UClassID)&fgClassID; } michael@0: * static char fgClassID; michael@0: * michael@0: * @return The class ID for this object. All objects of a given class have the michael@0: * same class ID. Objects of other classes have different class IDs. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const = 0; michael@0: michael@0: /** michael@0: * Returns the calendar type name string for this Calendar object. michael@0: * The returned string is the legacy ICU calendar attribute value, michael@0: * for example, "gregorian" or "japanese". michael@0: * michael@0: * See type="old type name" for the calendar attribute of locale IDs michael@0: * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions michael@0: * michael@0: * Sample code for getting the LDML/BCP 47 calendar key value: michael@0: * \code michael@0: * const char *calType = cal->getType(); michael@0: * if (0 == strcmp(calType, "unknown")) { michael@0: * // deal with unknown calendar type michael@0: * } else { michael@0: * string localeID("root@calendar="); michael@0: * localeID.append(calType); michael@0: * char langTag[100]; michael@0: * UErrorCode errorCode = U_ZERO_ERROR; michael@0: * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), TRUE, &errorCode); michael@0: * if (U_FAILURE(errorCode)) { michael@0: * // deal with errors & overflow michael@0: * } michael@0: * string lang(langTag, length); michael@0: * size_t caPos = lang.find("-ca-"); michael@0: * lang.erase(0, caPos + 4); michael@0: * // lang now contains the LDML calendar type michael@0: * } michael@0: * \endcode michael@0: * michael@0: * @return legacy calendar type name string michael@0: * @stable ICU 49 michael@0: */ michael@0: virtual const char * getType() const = 0; michael@0: michael@0: /** michael@0: * Returns whether the given day of the week is a weekday, a weekend day, michael@0: * or a day that transitions from one to the other, for the locale and michael@0: * calendar system associated with this Calendar (the locale's region is michael@0: * often the most determinant factor). If a transition occurs at midnight, michael@0: * then the days before and after the transition will have the michael@0: * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time michael@0: * other than midnight, then the day of the transition will have michael@0: * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the michael@0: * method getWeekendTransition() will return the point of michael@0: * transition. michael@0: * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY). michael@0: * @param status The error code for the operation. michael@0: * @return The UCalendarWeekdayType for the day of the week. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns the time during the day at which the weekend begins or ends in michael@0: * this calendar system. If getDayOfWeekType() returns UCAL_WEEKEND_ONSET michael@0: * for the specified dayOfWeek, return the time at which the weekend begins. michael@0: * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek, michael@0: * return the time at which the weekend ends. If getDayOfWeekType() returns michael@0: * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition michael@0: * (U_ILLEGAL_ARGUMENT_ERROR). michael@0: * @param dayOfWeek The day of the week for which the weekend transition time is michael@0: * desired (UCAL_SUNDAY..UCAL_SATURDAY). michael@0: * @param status The error code for the operation. michael@0: * @return The milliseconds after midnight at which the weekend begins or ends. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns TRUE if the given UDate is in the weekend in michael@0: * this calendar system. michael@0: * @param date The UDate in question. michael@0: * @param status The error code for the operation. michael@0: * @return TRUE if the given UDate is in the weekend in michael@0: * this calendar system, FALSE otherwise. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual UBool isWeekend(UDate date, UErrorCode &status) const; michael@0: michael@0: /** michael@0: * Returns TRUE if this Calendar's current date-time is in the weekend in michael@0: * this calendar system. michael@0: * @return TRUE if this Calendar's current date-time is in the weekend in michael@0: * this calendar system, FALSE otherwise. michael@0: * @stable ICU 4.4 michael@0: */ michael@0: virtual UBool isWeekend(void) const; michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Constructs a Calendar with the default time zone as returned by michael@0: * TimeZone::createInstance(), and the default locale. michael@0: * michael@0: * @param success Indicates the status of Calendar object construction. Returns michael@0: * U_ZERO_ERROR if constructed successfully. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Calendar(UErrorCode& success); michael@0: michael@0: /** michael@0: * Copy constructor michael@0: * michael@0: * @param source Calendar object to be copied from michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Calendar(const Calendar& source); michael@0: michael@0: /** michael@0: * Default assignment operator michael@0: * michael@0: * @param right Calendar object to be copied michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Calendar& operator=(const Calendar& right); michael@0: michael@0: /** michael@0: * Constructs a Calendar with the given time zone and locale. Clients are no longer michael@0: * responsible for deleting the given time zone object after it's adopted. michael@0: * michael@0: * @param zone The given time zone. michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the status of Calendar object construction. Returns michael@0: * U_ZERO_ERROR if constructed successfully. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success); michael@0: michael@0: /** michael@0: * Constructs a Calendar with the given time zone and locale. michael@0: * michael@0: * @param zone The given time zone. michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the status of Calendar object construction. Returns michael@0: * U_ZERO_ERROR if constructed successfully. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success); michael@0: michael@0: /** michael@0: * Converts Calendar's time field values to GMT as milliseconds. michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void computeTime(UErrorCode& status); michael@0: michael@0: /** michael@0: * Converts GMT as milliseconds to time field values. This allows you to sync up the michael@0: * time field values with a new time that is set for the calendar. This method michael@0: * does NOT recompute the time first; to recompute the time, then the fields, use michael@0: * the method complete(). michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void computeFields(UErrorCode& status); michael@0: michael@0: /** michael@0: * Gets this Calendar's current time as a long. michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @return the current time as UTC milliseconds from the epoch. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: double getTimeInMillis(UErrorCode& status) const; michael@0: michael@0: /** michael@0: * Sets this Calendar's current time from the given long value. michael@0: * @param millis the new time in UTC milliseconds from the epoch. michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setTimeInMillis( double millis, UErrorCode& status ); michael@0: michael@0: /** michael@0: * Recomputes the current time from currently set fields, and then fills in any michael@0: * unset fields in the time field list. michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void complete(UErrorCode& status); michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Gets the value for a given time field. Subclasses can use this function to get michael@0: * field values without forcing recomputation of time. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The value for the given time field. michael@0: * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead. michael@0: */ michael@0: inline int32_t internalGet(EDateFields field) const {return fFields[field];} michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Gets the value for a given time field. Subclasses can use this function to get michael@0: * field values without forcing recomputation of time. If the field's stamp is UNSET, michael@0: * the defaultValue is used. michael@0: * michael@0: * @param field The given time field. michael@0: * @param defaultValue a default value used if the field is unset. michael@0: * @return The value for the given time field. michael@0: * @internal michael@0: */ michael@0: inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {return fStamp[field]>kUnset ? fFields[field] : defaultValue;} michael@0: michael@0: /** michael@0: * Gets the value for a given time field. Subclasses can use this function to get michael@0: * field values without forcing recomputation of time. michael@0: * michael@0: * @param field The given time field. michael@0: * @return The value for the given time field. michael@0: * @internal michael@0: */ michael@0: inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];} michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: /** michael@0: * Sets the value for a given time field. This is a fast internal method for michael@0: * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet michael@0: * flags. michael@0: * michael@0: * @param field The given time field. michael@0: * @param value The value for the given time field. michael@0: * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead. michael@0: */ michael@0: void internalSet(EDateFields field, int32_t value); michael@0: #endif /* U_HIDE_DEPRECATED_API */ michael@0: michael@0: /** michael@0: * Sets the value for a given time field. This is a fast internal method for michael@0: * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet michael@0: * flags. michael@0: * michael@0: * @param field The given time field. michael@0: * @param value The value for the given time field. michael@0: * @stable ICU 2.6. michael@0: */ michael@0: inline void internalSet(UCalendarDateFields field, int32_t value); michael@0: michael@0: /** michael@0: * Prepare this calendar for computing the actual minimum or maximum. michael@0: * This method modifies this calendar's fields; it is called on a michael@0: * temporary calendar. michael@0: * @internal michael@0: */ michael@0: virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status); michael@0: michael@0: /** michael@0: * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields). michael@0: * @internal michael@0: */ michael@0: enum ELimitType { michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: UCAL_LIMIT_MINIMUM = 0, michael@0: UCAL_LIMIT_GREATEST_MINIMUM, michael@0: UCAL_LIMIT_LEAST_MAXIMUM, michael@0: UCAL_LIMIT_MAXIMUM, michael@0: UCAL_LIMIT_COUNT michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: }; michael@0: michael@0: /** michael@0: * Subclass API for defining limits of different types. michael@0: * Subclasses must implement this method to return limits for the michael@0: * following fields: michael@0: * michael@0: *

UCAL_ERA
michael@0:      * UCAL_YEAR
michael@0:      * UCAL_MONTH
michael@0:      * UCAL_WEEK_OF_YEAR
michael@0:      * UCAL_WEEK_OF_MONTH
michael@0:      * UCAL_DATE (DAY_OF_MONTH on Java)
michael@0:      * UCAL_DAY_OF_YEAR
michael@0:      * UCAL_DAY_OF_WEEK_IN_MONTH
michael@0:      * UCAL_YEAR_WOY
michael@0:      * UCAL_EXTENDED_YEAR
michael@0: * michael@0: * @param field one of the above field numbers michael@0: * @param limitType one of MINIMUM, GREATEST_MINIMUM, michael@0: * LEAST_MAXIMUM, or MAXIMUM michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0; michael@0: michael@0: /** michael@0: * Return a limit for a field. michael@0: * @param field the field, from 0..UCAL_MAX_FIELD michael@0: * @param limitType the type specifier for the limit michael@0: * @see #ELimitType michael@0: * @internal michael@0: */ michael@0: virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const; michael@0: michael@0: michael@0: /** michael@0: * Return the Julian day number of day before the first day of the michael@0: * given month in the given extended year. Subclasses should override michael@0: * this method to implement their calendar system. michael@0: * @param eyear the extended year michael@0: * @param month the zero-based month, or 0 if useMonth is false michael@0: * @param useMonth if false, compute the day before the first day of michael@0: * the given year, otherwise, compute the day before the first day of michael@0: * the given month michael@0: * @return the Julian day number of the day before the first michael@0: * day of the given month and year michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, michael@0: UBool useMonth) const = 0; michael@0: michael@0: /** michael@0: * Return the number of days in the given month of the given extended michael@0: * year of this calendar system. Subclasses should override this michael@0: * method if they can provide a more correct or more efficient michael@0: * implementation than the default implementation in Calendar. michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const ; michael@0: michael@0: /** michael@0: * Return the number of days in the given extended year of this michael@0: * calendar system. Subclasses should override this method if they can michael@0: * provide a more correct or more efficient implementation than the michael@0: * default implementation in Calendar. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual int32_t handleGetYearLength(int32_t eyear) const; michael@0: michael@0: michael@0: /** michael@0: * Return the extended year defined by the current fields. This will michael@0: * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such michael@0: * as UCAL_ERA) specific to the calendar system, depending on which set of michael@0: * fields is newer. michael@0: * @return the extended year michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetExtendedYear() = 0; michael@0: michael@0: /** michael@0: * Subclasses may override this. This method calls michael@0: * handleGetMonthLength() to obtain the calendar-specific month michael@0: * length. michael@0: * @param bestField which field to use to calculate the date michael@0: * @return julian day specified by calendar fields. michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField); michael@0: michael@0: /** michael@0: * Subclasses must override this to convert from week fields michael@0: * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case michael@0: * where YEAR, EXTENDED_YEAR are not set. michael@0: * The Calendar implementation assumes yearWoy is in extended gregorian form michael@0: * @return the extended year, UCAL_EXTENDED_YEAR michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Compute the Julian day from fields. Will determine whether to use michael@0: * the JULIAN_DAY field directly, or other fields. michael@0: * @return the julian day michael@0: * @internal michael@0: */ michael@0: int32_t computeJulianDay(); michael@0: michael@0: /** michael@0: * Compute the milliseconds in the day from the fields. This is a michael@0: * value from 0 to 23:59:59.999 inclusive, unless fields are out of michael@0: * range, in which case it can be an arbitrary value. This value michael@0: * reflects local zone wall time. michael@0: * @internal michael@0: */ michael@0: int32_t computeMillisInDay(); michael@0: michael@0: /** michael@0: * This method can assume EXTENDED_YEAR has been set. michael@0: * @param millis milliseconds of the date fields michael@0: * @param millisInDay milliseconds of the time fields; may be out michael@0: * or range. michael@0: * @param ec Output param set to failure code on function return michael@0: * when this function fails. michael@0: * @internal michael@0: */ michael@0: int32_t computeZoneOffset(double millis, int32_t millisInDay, UErrorCode &ec); michael@0: michael@0: michael@0: /** michael@0: * Determine the best stamp in a range. michael@0: * @param start first enum to look at michael@0: * @param end last enum to look at michael@0: * @param bestSoFar stamp prior to function call michael@0: * @return the stamp value of the best stamp michael@0: * @internal michael@0: */ michael@0: int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const; michael@0: michael@0: /** michael@0: * Values for field resolution tables michael@0: * @see #resolveFields michael@0: * @internal michael@0: */ michael@0: enum { michael@0: /** Marker for end of resolve set (row or group). */ michael@0: kResolveSTOP = -1, michael@0: /** Value to be bitwised "ORed" against resolve table field values for remapping. Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned, but will not examine the value of UCAL_DATE. */ michael@0: kResolveRemap = 32 michael@0: }; michael@0: michael@0: /** michael@0: * Precedence table for Dates michael@0: * @see #resolveFields michael@0: * @internal michael@0: */ michael@0: static const UFieldResolutionTable kDatePrecedence[]; michael@0: michael@0: /** michael@0: * Precedence table for Year michael@0: * @see #resolveFields michael@0: * @internal michael@0: */ michael@0: static const UFieldResolutionTable kYearPrecedence[]; michael@0: michael@0: /** michael@0: * Precedence table for Day of Week michael@0: * @see #resolveFields michael@0: * @internal michael@0: */ michael@0: static const UFieldResolutionTable kDOWPrecedence[]; michael@0: michael@0: /** michael@0: * Given a precedence table, return the newest field combination in michael@0: * the table, or UCAL_FIELD_COUNT if none is found. michael@0: * michael@0: *

The precedence table is a 3-dimensional array of integers. It michael@0: * may be thought of as an array of groups. Each group is an array of michael@0: * lines. Each line is an array of field numbers. Within a line, if michael@0: * all fields are set, then the time stamp of the line is taken to be michael@0: * the stamp of the most recently set field. If any field of a line is michael@0: * unset, then the line fails to match. Within a group, the line with michael@0: * the newest time stamp is selected. The first field of the line is michael@0: * returned to indicate which line matched. michael@0: * michael@0: *

In some cases, it may be desirable to map a line to field that michael@0: * whose stamp is NOT examined. For example, if the best field is michael@0: * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In michael@0: * order to do this, insert the value kResolveRemap | F at michael@0: * the start of the line, where F is the desired return michael@0: * field value. This field will NOT be examined; it only determines michael@0: * the return value if the other fields in the line are the newest. michael@0: * michael@0: *

If all lines of a group contain at least one unset field, then no michael@0: * line will match, and the group as a whole will fail to match. In michael@0: * that case, the next group will be processed. If all groups fail to michael@0: * match, then UCAL_FIELD_COUNT is returned. michael@0: * @internal michael@0: */ michael@0: UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual const UFieldResolutionTable* getFieldResolutionTable() const; michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Return the field that is newer, either defaultField, or michael@0: * alternateField. If neither is newer or neither is set, return defaultField. michael@0: * @internal michael@0: */ michael@0: UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const; michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: michael@0: private: michael@0: /** michael@0: * Helper function for calculating limits by trial and error michael@0: * @param field The field being investigated michael@0: * @param startValue starting (least max) value of field michael@0: * @param endValue ending (greatest max) value of field michael@0: * @param status return type michael@0: * @internal michael@0: */ michael@0: int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const; michael@0: michael@0: michael@0: protected: michael@0: /** michael@0: * The flag which indicates if the current time is set in the calendar. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool fIsTimeSet; michael@0: michael@0: /** michael@0: * True if the fields are in sync with the currently set time of this Calendar. michael@0: * If false, then the next attempt to get the value of a field will michael@0: * force a recomputation of all fields from the current value of the time michael@0: * field. michael@0: *

michael@0: * This should really be named areFieldsInSync, but the old name is retained michael@0: * for backward compatibility. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool fAreFieldsSet; michael@0: michael@0: /** michael@0: * True if all of the fields have been set. This is initially false, and set to michael@0: * true by computeFields(). michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool fAreAllFieldsSet; michael@0: michael@0: /** michael@0: * True if all fields have been virtually set, but have not yet been michael@0: * computed. This occurs only in setTimeInMillis(). A calendar set michael@0: * to this state will compute all fields from the time if it becomes michael@0: * necessary, but otherwise will delay such computation. michael@0: * @stable ICU 3.0 michael@0: */ michael@0: UBool fAreFieldsVirtuallySet; michael@0: michael@0: /** michael@0: * Get the current time without recomputing. michael@0: * michael@0: * @return the current time without recomputing. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UDate internalGetTime(void) const { return fTime; } michael@0: michael@0: /** michael@0: * Set the current time without affecting flags or fields. michael@0: * michael@0: * @param time The time to be set michael@0: * @return the current time without recomputing. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void internalSetTime(UDate time) { fTime = time; } michael@0: michael@0: /** michael@0: * The time fields containing values into which the millis is computed. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t fFields[UCAL_FIELD_COUNT]; michael@0: michael@0: /** michael@0: * The flags which tell if a specified time field for the calendar is set. michael@0: * @deprecated ICU 2.8 use (fStamp[n]!=kUnset) michael@0: */ michael@0: UBool fIsSet[UCAL_FIELD_COUNT]; michael@0: michael@0: /** Special values of stamp[] michael@0: * @stable ICU 2.0 michael@0: */ michael@0: enum { michael@0: kUnset = 0, michael@0: kInternallySet, michael@0: kMinimumUserStamp michael@0: }; michael@0: michael@0: /** michael@0: * Pseudo-time-stamps which specify when each field was set. There michael@0: * are two special values, UNSET and INTERNALLY_SET. Values from michael@0: * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t fStamp[UCAL_FIELD_COUNT]; michael@0: michael@0: /** michael@0: * Subclasses may override this method to compute several fields michael@0: * specific to each calendar system. These are: michael@0: * michael@0: *

michael@0: * michael@0: * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which michael@0: * will be set when this method is called. Subclasses can also call michael@0: * the getGregorianXxx() methods to obtain Gregorian calendar michael@0: * equivalents for the given Julian day. michael@0: * michael@0: *

In addition, subclasses should compute any subclass-specific michael@0: * fields, that is, fields from BASE_FIELD_COUNT to michael@0: * getFieldCount() - 1. michael@0: * michael@0: *

The default implementation in Calendar implements michael@0: * a pure proleptic Gregorian calendar. michael@0: * @internal michael@0: */ michael@0: virtual void handleComputeFields(int32_t julianDay, UErrorCode &status); michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Return the extended year on the Gregorian calendar as computed by michael@0: * computeGregorianFields(). michael@0: * @internal michael@0: */ michael@0: int32_t getGregorianYear() const { michael@0: return fGregorianYear; michael@0: } michael@0: michael@0: /** michael@0: * Return the month (0-based) on the Gregorian calendar as computed by michael@0: * computeGregorianFields(). michael@0: * @internal michael@0: */ michael@0: int32_t getGregorianMonth() const { michael@0: return fGregorianMonth; michael@0: } michael@0: michael@0: /** michael@0: * Return the day of year (1-based) on the Gregorian calendar as michael@0: * computed by computeGregorianFields(). michael@0: * @internal michael@0: */ michael@0: int32_t getGregorianDayOfYear() const { michael@0: return fGregorianDayOfYear; michael@0: } michael@0: michael@0: /** michael@0: * Return the day of month (1-based) on the Gregorian calendar as michael@0: * computed by computeGregorianFields(). michael@0: * @internal michael@0: */ michael@0: int32_t getGregorianDayOfMonth() const { michael@0: return fGregorianDayOfMonth; michael@0: } michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Called by computeJulianDay. Returns the default month (0-based) for the year, michael@0: * taking year and era into account. Defaults to 0 for Gregorian, which doesn't care. michael@0: * @param eyear The extended year michael@0: * @internal michael@0: */ michael@0: virtual int32_t getDefaultMonthInYear(int32_t eyear) ; michael@0: michael@0: michael@0: /** michael@0: * Called by computeJulianDay. Returns the default day (1-based) for the month, michael@0: * taking currently-set year and era into account. Defaults to 1 for Gregorian. michael@0: * @param eyear the extended year michael@0: * @param month the month in the year michael@0: * @internal michael@0: */ michael@0: virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month); michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Protected utility methods for use by subclasses. These are very handy michael@0: // for implementing add, roll, and computeFields. michael@0: //------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Adjust the specified field so that it is within michael@0: * the allowable range for the date to which this calendar is set. michael@0: * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH} michael@0: * field for a calendar set to April 31 would cause it to be set michael@0: * to April 30. michael@0: *

michael@0: * Subclassing: michael@0: *
michael@0: * This utility method is intended for use by subclasses that need to implement michael@0: * their own overrides of {@link #roll roll} and {@link #add add}. michael@0: *

michael@0: * Note: michael@0: * pinField is implemented in terms of michael@0: * {@link #getActualMinimum getActualMinimum} michael@0: * and {@link #getActualMaximum getActualMaximum}. If either of those methods uses michael@0: * a slow, iterative algorithm for a particular field, it would be michael@0: * unwise to attempt to call pinField for that field. If you michael@0: * really do need to do so, you should override this method to do michael@0: * something more efficient for that field. michael@0: *

michael@0: * @param field The calendar field whose value should be pinned. michael@0: * @param status Output param set to failure code on function return michael@0: * when this function fails. michael@0: * michael@0: * @see #getActualMinimum michael@0: * @see #getActualMaximum michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void pinField(UCalendarDateFields field, UErrorCode& status); michael@0: michael@0: /** michael@0: * Return the week number of a day, within a period. This may be the week number in michael@0: * a year or the week number in a month. Usually this will be a value >= 1, but if michael@0: * some initial days of the period are excluded from week 1, because michael@0: * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then michael@0: * the week number will be zero for those michael@0: * initial days. This method requires the day number and day of week for some michael@0: * known date in the period in order to determine the day of week michael@0: * on the desired day. michael@0: *

michael@0: * Subclassing: michael@0: *
michael@0: * This method is intended for use by subclasses in implementing their michael@0: * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods. michael@0: * It is often useful in {@link #getActualMinimum getActualMinimum} and michael@0: * {@link #getActualMaximum getActualMaximum} as well. michael@0: *

michael@0: * This variant is handy for computing the week number of some other michael@0: * day of a period (often the first or last day of the period) when its day michael@0: * of the week is not known but the day number and day of week for some other michael@0: * day in the period (e.g. the current date) is known. michael@0: *

michael@0: * @param desiredDay The {@link #UCalendarDateFields DAY_OF_YEAR} or michael@0: * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired. michael@0: * Should be 1 for the first day of the period. michael@0: * michael@0: * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} michael@0: * or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose michael@0: * {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the michael@0: * knownDayOfWeek parameter. michael@0: * Should be 1 for first day of period. michael@0: * michael@0: * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day michael@0: * corresponding to the knownDayOfPeriod parameter. michael@0: * 1-based with 1=Sunday. michael@0: * michael@0: * @return The week number (one-based), or zero if the day falls before michael@0: * the first week because michael@0: * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} michael@0: * is more than one. michael@0: * michael@0: * @stable ICU 2.8 michael@0: */ michael@0: int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek); michael@0: michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Return the week number of a day, within a period. This may be the week number in michael@0: * a year, or the week number in a month. Usually this will be a value >= 1, but if michael@0: * some initial days of the period are excluded from week 1, because michael@0: * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, michael@0: * then the week number will be zero for those michael@0: * initial days. This method requires the day of week for the given date in order to michael@0: * determine the result. michael@0: *

michael@0: * Subclassing: michael@0: *
michael@0: * This method is intended for use by subclasses in implementing their michael@0: * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods. michael@0: * It is often useful in {@link #getActualMinimum getActualMinimum} and michael@0: * {@link #getActualMaximum getActualMaximum} as well. michael@0: *

michael@0: * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} or michael@0: * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired. michael@0: * Should be 1 for the first day of the period. michael@0: * michael@0: * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day michael@0: * corresponding to the dayOfPeriod parameter. michael@0: * 1-based with 1=Sunday. michael@0: * michael@0: * @return The week number (one-based), or zero if the day falls before michael@0: * the first week because michael@0: * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} michael@0: * is more than one. michael@0: * @internal michael@0: */ michael@0: inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek); michael@0: michael@0: /** michael@0: * returns the local DOW, valid range 0..6 michael@0: * @internal michael@0: */ michael@0: int32_t getLocalDOW(); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * The next available value for fStamp[] michael@0: */ michael@0: int32_t fNextStamp;// = MINIMUM_USER_STAMP; michael@0: michael@0: /** michael@0: * Recalculates the time stamp array (fStamp). michael@0: * Resets fNextStamp to lowest next stamp value. michael@0: */ michael@0: void recalculateStamp(); michael@0: michael@0: /** michael@0: * The current time set for the calendar. michael@0: */ michael@0: UDate fTime; michael@0: michael@0: /** michael@0: * @see #setLenient michael@0: */ michael@0: UBool fLenient; michael@0: michael@0: /** michael@0: * Time zone affects the time calculation done by Calendar. Calendar subclasses use michael@0: * the time zone data to produce the local time. michael@0: */ michael@0: TimeZone* fZone; michael@0: michael@0: /** michael@0: * Option for rpeated wall time michael@0: * @see #setRepeatedWallTimeOption michael@0: */ michael@0: UCalendarWallTimeOption fRepeatedWallTime; michael@0: michael@0: /** michael@0: * Option for skipped wall time michael@0: * @see #setSkippedWallTimeOption michael@0: */ michael@0: UCalendarWallTimeOption fSkippedWallTime; michael@0: michael@0: /** michael@0: * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are michael@0: * used to figure out the week count for a specific date for a given locale. These michael@0: * must be set when a Calendar is constructed. For example, in US locale, michael@0: * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure michael@0: * out the week count for a specific date for a given locale. These must be set when michael@0: * a Calendar is constructed. michael@0: */ michael@0: UCalendarDaysOfWeek fFirstDayOfWeek; michael@0: uint8_t fMinimalDaysInFirstWeek; michael@0: UCalendarDaysOfWeek fWeekendOnset; michael@0: int32_t fWeekendOnsetMillis; michael@0: UCalendarDaysOfWeek fWeekendCease; michael@0: int32_t fWeekendCeaseMillis; michael@0: michael@0: /** michael@0: * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction michael@0: * time. michael@0: * michael@0: * @param desiredLocale The given locale. michael@0: * @param type The calendar type identifier, e.g: gregorian, buddhist, etc. michael@0: * @param success Indicates the status of setting the week count data from michael@0: * the resource for the given locale. Returns U_ZERO_ERROR if michael@0: * constructed successfully. michael@0: */ michael@0: void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success); michael@0: michael@0: /** michael@0: * Recompute the time and update the status fields isTimeSet michael@0: * and areFieldsSet. Callers should check isTimeSet and only michael@0: * call this method if isTimeSet is false. michael@0: * michael@0: * @param status Output param set to success/failure code on exit. If any value michael@0: * previously set in the time field is invalid or restricted by michael@0: * leniency, this will be set to an error status. michael@0: */ michael@0: void updateTime(UErrorCode& status); michael@0: michael@0: /** michael@0: * The Gregorian year, as computed by computeGregorianFields() and michael@0: * returned by getGregorianYear(). michael@0: * @see #computeGregorianFields michael@0: */ michael@0: int32_t fGregorianYear; michael@0: michael@0: /** michael@0: * The Gregorian month, as computed by computeGregorianFields() and michael@0: * returned by getGregorianMonth(). michael@0: * @see #computeGregorianFields michael@0: */ michael@0: int32_t fGregorianMonth; michael@0: michael@0: /** michael@0: * The Gregorian day of the year, as computed by michael@0: * computeGregorianFields() and returned by getGregorianDayOfYear(). michael@0: * @see #computeGregorianFields michael@0: */ michael@0: int32_t fGregorianDayOfYear; michael@0: michael@0: /** michael@0: * The Gregorian day of the month, as computed by michael@0: * computeGregorianFields() and returned by getGregorianDayOfMonth(). michael@0: * @see #computeGregorianFields michael@0: */ michael@0: int32_t fGregorianDayOfMonth; michael@0: michael@0: /* calculations */ michael@0: michael@0: /** michael@0: * Compute the Gregorian calendar year, month, and day of month from michael@0: * the given Julian day. These values are not stored in fields, but in michael@0: * member variables gregorianXxx. Also compute the DAY_OF_WEEK and michael@0: * DOW_LOCAL fields. michael@0: */ michael@0: void computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec); michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Compute the Gregorian calendar year, month, and day of month from the michael@0: * Julian day. These values are not stored in fields, but in member michael@0: * variables gregorianXxx. They are used for time zone computations and by michael@0: * subclasses that are Gregorian derivatives. Subclasses may call this michael@0: * method to perform a Gregorian calendar millis->fields computation. michael@0: */ michael@0: void computeGregorianFields(int32_t julianDay, UErrorCode &ec); michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH, michael@0: * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR, michael@0: * DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the michael@0: * subclass based on the calendar system. michael@0: * michael@0: *

The YEAR_WOY field is computed simplistically. It is equal to YEAR michael@0: * most of the time, but at the year boundary it may be adjusted to YEAR-1 michael@0: * or YEAR+1 to reflect the overlap of a week into an adjacent year. In michael@0: * this case, a simple increment or decrement is performed on YEAR, even michael@0: * though this may yield an invalid YEAR value. For instance, if the YEAR michael@0: * is part of a calendar system with an N-year cycle field CYCLE, then michael@0: * incrementing the YEAR may involve incrementing CYCLE and setting YEAR michael@0: * back to 0 or 1. This is not handled by this code, and in fact cannot be michael@0: * simply handled without having subclasses define an entire parallel set of michael@0: * fields for fields larger than or equal to a year. This additional michael@0: * complexity is not warranted, since the intention of the YEAR_WOY field is michael@0: * to support ISO 8601 notation, so it will typically be used with a michael@0: * proleptic Gregorian calendar, which has no field larger than a year. michael@0: */ michael@0: void computeWeekFields(UErrorCode &ec); michael@0: michael@0: michael@0: /** michael@0: * Ensure that each field is within its valid range by calling {@link michael@0: * #validateField(int, int&)} on each field that has been set. This method michael@0: * should only be called if this calendar is not lenient. michael@0: * @see #isLenient michael@0: * @see #validateField(int, int&) michael@0: * @internal michael@0: */ michael@0: void validateFields(UErrorCode &status); michael@0: michael@0: /** michael@0: * Validate a single field of this calendar. Subclasses should michael@0: * override this method to validate any calendar-specific fields. michael@0: * Generic fields can be handled by michael@0: * Calendar::validateField(). michael@0: * @see #validateField(int, int, int, int&) michael@0: * @internal michael@0: */ michael@0: virtual void validateField(UCalendarDateFields field, UErrorCode &status); michael@0: michael@0: /** michael@0: * Validate a single field of this calendar given its minimum and michael@0: * maximum allowed value. If the field is out of range, michael@0: * U_ILLEGAL_ARGUMENT_ERROR will be set. Subclasses may michael@0: * use this method in their implementation of {@link michael@0: * #validateField(int, int&)}. michael@0: * @internal michael@0: */ michael@0: void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status); michael@0: michael@0: protected: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Convert a quasi Julian date to the day of the week. The Julian date used here is michael@0: * not a true Julian date, since it is measured from midnight, not noon. Return michael@0: * value is one-based. michael@0: * michael@0: * @param julian The given Julian date number. michael@0: * @return Day number from 1..7 (SUN..SAT). michael@0: * @internal michael@0: */ michael@0: static uint8_t julianDayToDayOfWeek(double julian); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: char validLocale[ULOC_FULLNAME_CAPACITY]; michael@0: char actualLocale[ULOC_FULLNAME_CAPACITY]; michael@0: michael@0: public: michael@0: #if !UCONFIG_NO_SERVICE michael@0: /** michael@0: * INTERNAL FOR 2.6 -- Registration. michael@0: */ michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** michael@0: * Return a StringEnumeration over the locales available at the time of the call, michael@0: * including registered locales. michael@0: * @return a StringEnumeration over the locales available at the time of the call michael@0: * @internal michael@0: */ michael@0: static StringEnumeration* getAvailableLocales(void); michael@0: michael@0: /** michael@0: * Register a new Calendar factory. The factory will be adopted. michael@0: * INTERNAL in 2.6 michael@0: * @param toAdopt the factory instance to be adopted michael@0: * @param status the in/out status code, no special meanings are assigned michael@0: * @return a registry key that can be used to unregister this factory michael@0: * @internal michael@0: */ michael@0: static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status); michael@0: michael@0: /** michael@0: * Unregister a previously-registered CalendarFactory using the key returned from the michael@0: * register call. Key becomes invalid after a successful call and should not be used again. michael@0: * The CalendarFactory corresponding to the key will be deleted. michael@0: * INTERNAL in 2.6 michael@0: * @param key the registry key returned by a previous call to registerFactory michael@0: * @param status the in/out status code, no special meanings are assigned michael@0: * @return TRUE if the factory for the key was successfully unregistered michael@0: * @internal michael@0: */ michael@0: static UBool unregister(URegistryKey key, UErrorCode& status); michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: /** michael@0: * Multiple Calendar Implementation michael@0: * @internal michael@0: */ michael@0: friend class CalendarFactory; michael@0: michael@0: /** michael@0: * Multiple Calendar Implementation michael@0: * @internal michael@0: */ michael@0: friend class CalendarService; michael@0: michael@0: /** michael@0: * Multiple Calendar Implementation michael@0: * @internal michael@0: */ michael@0: friend class DefaultCalendarFactory; michael@0: #endif /* !UCONFIG_NO_SERVICE */ michael@0: michael@0: /** michael@0: * @return TRUE if this calendar has a default century (i.e. 03 -> 2003) michael@0: * @internal michael@0: */ michael@0: virtual UBool haveDefaultCentury() const = 0; michael@0: michael@0: /** michael@0: * @return the start of the default century, as a UDate michael@0: * @internal michael@0: */ michael@0: virtual UDate defaultCenturyStart() const = 0; michael@0: /** michael@0: * @return the beginning year of the default century, as a year michael@0: * @internal michael@0: */ michael@0: virtual int32_t defaultCenturyStartYear() const = 0; michael@0: michael@0: /** Get the locale for this calendar object. You can choose between valid and actual locale. michael@0: * @param type type of the locale we're looking for (valid or actual) michael@0: * @param status error code for the operation michael@0: * @return the locale michael@0: * @stable ICU 2.8 michael@0: */ michael@0: Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const; michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: /** Get the locale for this calendar object. You can choose between valid and actual locale. michael@0: * @param type type of the locale we're looking for (valid or actual) michael@0: * @param status error code for the operation michael@0: * @return the locale michael@0: * @internal michael@0: */ michael@0: const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const; michael@0: #endif /* U_HIDE_INTERNAL_API */ michael@0: michael@0: private: michael@0: /** michael@0: * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone michael@0: * is not an instance of BasicTimeZone. michael@0: */ michael@0: BasicTimeZone* getBasicTimeZone() const; michael@0: }; michael@0: michael@0: // ------------------------------------- michael@0: michael@0: inline Calendar* michael@0: Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode) michael@0: { michael@0: // since the Locale isn't specified, use the default locale michael@0: return createInstance(zone, Locale::getDefault(), errorCode); michael@0: } michael@0: michael@0: // ------------------------------------- michael@0: michael@0: inline void michael@0: Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status) michael@0: { michael@0: roll(field, (int32_t)(up ? +1 : -1), status); michael@0: } michael@0: michael@0: #ifndef U_HIDE_DEPRECATED_API michael@0: inline void michael@0: Calendar::roll(EDateFields field, UBool up, UErrorCode& status) michael@0: { michael@0: roll((UCalendarDateFields) field, up, status); michael@0: } michael@0: #endif michael@0: michael@0: michael@0: // ------------------------------------- michael@0: michael@0: /** michael@0: * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and michael@0: * fUserSetZoneOffset, as well as the isSet[] array. michael@0: */ michael@0: michael@0: inline void michael@0: Calendar::internalSet(UCalendarDateFields field, int32_t value) michael@0: { michael@0: fFields[field] = value; michael@0: fStamp[field] = kInternallySet; michael@0: fIsSet[field] = TRUE; // Remove later michael@0: } michael@0: michael@0: michael@0: #ifndef U_HIDE_INTERNAL_API michael@0: inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek) michael@0: { michael@0: return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek); michael@0: } michael@0: #endif michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: michael@0: #endif // _CALENDAR