intl/icu/source/i18n/unicode/gregocal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/unicode/gregocal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,777 @@
     1.4 +/*
     1.5 +* Copyright (C) 1997-2013, International Business Machines Corporation and others.
     1.6 +* All Rights Reserved.
     1.7 +********************************************************************************
     1.8 +*
     1.9 +* File GREGOCAL.H
    1.10 +*
    1.11 +* Modification History:
    1.12 +*
    1.13 +*   Date        Name        Description
    1.14 +*   04/22/97    aliu        Overhauled header.
    1.15 +*    07/28/98    stephen        Sync with JDK 1.2
    1.16 +*    09/04/98    stephen        Re-sync with JDK 8/31 putback
    1.17 +*    09/14/98    stephen        Changed type of kOneDay, kOneWeek to double.
    1.18 +*                            Fixed bug in roll()
    1.19 +*   10/15/99    aliu        Fixed j31, incorrect WEEK_OF_YEAR computation.
    1.20 +*                           Added documentation of WEEK_OF_YEAR computation.
    1.21 +*   10/15/99    aliu        Fixed j32, cannot set date to Feb 29 2000 AD.
    1.22 +*                           {JDK bug 4210209 4209272}
    1.23 +*   11/07/2003  srl         Update, clean up documentation.
    1.24 +********************************************************************************
    1.25 +*/
    1.26 +
    1.27 +#ifndef GREGOCAL_H
    1.28 +#define GREGOCAL_H
    1.29 +
    1.30 +#include "unicode/utypes.h"
    1.31 +
    1.32 +#if !UCONFIG_NO_FORMATTING
    1.33 +
    1.34 +#include "unicode/calendar.h"
    1.35 +
    1.36 +/**
    1.37 + * \file 
    1.38 + * \brief C++ API: Concrete class which provides the standard calendar.
    1.39 + */
    1.40 +
    1.41 +U_NAMESPACE_BEGIN
    1.42 +
    1.43 +/** 
    1.44 + * Concrete class which provides the standard calendar used by most of the world.
    1.45 + * <P>
    1.46 + * The standard (Gregorian) calendar has 2 eras, BC and AD.
    1.47 + * <P>
    1.48 + * This implementation handles a single discontinuity, which corresponds by default to
    1.49 + * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
    1.50 + * countries adopted the Gregorian calendar then, so this cutover date may be changed by
    1.51 + * the caller.
    1.52 + * <P>
    1.53 + * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
    1.54 + * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
    1.55 + * if desired for dates that are prior to the Gregorian changeover and which fall
    1.56 + * between January 1 and March 24.
    1.57 + *
    1.58 + * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
    1.59 + * 53.  Week 1 for a year is the first week that contains at least
    1.60 + * <code>getMinimalDaysInFirstWeek()</code> days from that year.  It thus
    1.61 + * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
    1.62 + * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
    1.63 + * Weeks between week 1 of one year and week 1 of the following year are
    1.64 + * numbered sequentially from 2 to 52 or 53 (as needed).
    1.65 + *
    1.66 + * <p>For example, January 1, 1998 was a Thursday.  If
    1.67 + * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
    1.68 + * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
    1.69 + * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
    1.70 + * on December 29, 1997, and ends on January 4, 1998.  If, however,
    1.71 + * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
    1.72 + * starts on January 4, 1998, and ends on January 10, 1998; the first three days
    1.73 + * of 1998 then are part of week 53 of 1997.
    1.74 + *
    1.75 + * <p>Example for using GregorianCalendar:
    1.76 + * <pre>
    1.77 + * \code
    1.78 + *     // get the supported ids for GMT-08:00 (Pacific Standard Time)
    1.79 + *     UErrorCode success = U_ZERO_ERROR;
    1.80 + *     const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
    1.81 + *     // if no ids were returned, something is wrong. get out.
    1.82 + *     if (ids == 0 || ids->count(success) == 0) {
    1.83 + *         return;
    1.84 + *     }
    1.85 + *
    1.86 + *     // begin output
    1.87 + *     cout << "Current Time" << endl;
    1.88 + *
    1.89 + *     // create a Pacific Standard Time time zone
    1.90 + *     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));
    1.91 + *
    1.92 + *     // set up rules for daylight savings time
    1.93 + *     pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
    1.94 + *     pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
    1.95 + *
    1.96 + *     // create a GregorianCalendar with the Pacific Daylight time zone
    1.97 + *     // and the current date and time
    1.98 + *     Calendar* calendar = new GregorianCalendar( pdt, success );
    1.99 + *
   1.100 + *     // print out a bunch of interesting things
   1.101 + *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
   1.102 + *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
   1.103 + *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
   1.104 + *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
   1.105 + *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
   1.106 + *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
   1.107 + *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
   1.108 + *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
   1.109 + *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
   1.110 + *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
   1.111 + *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
   1.112 + *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
   1.113 + *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
   1.114 + *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
   1.115 + *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
   1.116 + *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
   1.117 + *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
   1.118 + *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
   1.119 + *
   1.120 + *     cout << "Current Time, with hour reset to 3" << endl;
   1.121 + *     calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
   1.122 + *     calendar->set(UCAL_HOUR, 3);
   1.123 + *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
   1.124 + *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
   1.125 + *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
   1.126 + *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
   1.127 + *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
   1.128 + *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
   1.129 + *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
   1.130 + *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
   1.131 + *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
   1.132 + *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
   1.133 + *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
   1.134 + *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
   1.135 + *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
   1.136 + *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
   1.137 + *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
   1.138 + *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
   1.139 + *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
   1.140 + *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
   1.141 + *
   1.142 + *     if (U_FAILURE(success)) {
   1.143 + *         cout << "An error occured. success=" << u_errorName(success) << endl;
   1.144 + *     }
   1.145 + *
   1.146 + *     delete ids;
   1.147 + *     delete calendar; // also deletes pdt
   1.148 + * \endcode
   1.149 + * </pre>
   1.150 + * @stable ICU 2.0
   1.151 + */
   1.152 +class U_I18N_API GregorianCalendar: public Calendar {
   1.153 +public:
   1.154 +
   1.155 +    /**
   1.156 +     * Useful constants for GregorianCalendar and TimeZone.
   1.157 +     * @stable ICU 2.0
   1.158 +     */
   1.159 +    enum EEras {
   1.160 +        BC,
   1.161 +        AD
   1.162 +    };
   1.163 +
   1.164 +    /**
   1.165 +     * Constructs a default GregorianCalendar using the current time in the default time
   1.166 +     * zone with the default locale.
   1.167 +     *
   1.168 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.169 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.170 +     * @stable ICU 2.0
   1.171 +     */
   1.172 +    GregorianCalendar(UErrorCode& success);
   1.173 +
   1.174 +    /**
   1.175 +     * Constructs a GregorianCalendar based on the current time in the given time zone
   1.176 +     * with the default locale. Clients are no longer responsible for deleting the given
   1.177 +     * time zone object after it's adopted.
   1.178 +     *
   1.179 +     * @param zoneToAdopt     The given timezone.
   1.180 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.181 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.182 +     * @stable ICU 2.0
   1.183 +     */
   1.184 +    GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
   1.185 +
   1.186 +    /**
   1.187 +     * Constructs a GregorianCalendar based on the current time in the given time zone
   1.188 +     * with the default locale.
   1.189 +     *
   1.190 +     * @param zone     The given timezone.
   1.191 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.192 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.193 +     * @stable ICU 2.0
   1.194 +     */
   1.195 +    GregorianCalendar(const TimeZone& zone, UErrorCode& success);
   1.196 +
   1.197 +    /**
   1.198 +     * Constructs a GregorianCalendar based on the current time in the default time zone
   1.199 +     * with the given locale.
   1.200 +     *
   1.201 +     * @param aLocale  The given locale.
   1.202 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.203 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.204 +     * @stable ICU 2.0
   1.205 +     */
   1.206 +    GregorianCalendar(const Locale& aLocale, UErrorCode& success);
   1.207 +
   1.208 +    /**
   1.209 +     * Constructs a GregorianCalendar based on the current time in the given time zone
   1.210 +     * with the given locale. Clients are no longer responsible for deleting the given
   1.211 +     * time zone object after it's adopted.
   1.212 +     *
   1.213 +     * @param zoneToAdopt     The given timezone.
   1.214 +     * @param aLocale  The given locale.
   1.215 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.216 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.217 +     * @stable ICU 2.0
   1.218 +     */
   1.219 +    GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
   1.220 +
   1.221 +    /**
   1.222 +     * Constructs a GregorianCalendar based on the current time in the given time zone
   1.223 +     * with the given locale.
   1.224 +     *
   1.225 +     * @param zone     The given timezone.
   1.226 +     * @param aLocale  The given locale.
   1.227 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.228 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.229 +     * @stable ICU 2.0
   1.230 +     */
   1.231 +    GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
   1.232 +
   1.233 +    /**
   1.234 +     * Constructs a GregorianCalendar with the given AD date set in the default time
   1.235 +     * zone with the default locale.
   1.236 +     *
   1.237 +     * @param year     The value used to set the YEAR time field in the calendar.
   1.238 +     * @param month    The value used to set the MONTH time field in the calendar. Month
   1.239 +     *                 value is 0-based. e.g., 0 for January.
   1.240 +     * @param date     The value used to set the DATE time field in the calendar.
   1.241 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.242 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.243 +     * @stable ICU 2.0
   1.244 +     */
   1.245 +    GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
   1.246 +
   1.247 +    /**
   1.248 +     * Constructs a GregorianCalendar with the given AD date and time set for the
   1.249 +     * default time zone with the default locale.
   1.250 +     *
   1.251 +     * @param year     The value used to set the YEAR time field in the calendar.
   1.252 +     * @param month    The value used to set the MONTH time field in the calendar. Month
   1.253 +     *                 value is 0-based. e.g., 0 for January.
   1.254 +     * @param date     The value used to set the DATE time field in the calendar.
   1.255 +     * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
   1.256 +     * @param minute   The value used to set the MINUTE time field in the calendar.
   1.257 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.258 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.259 +     * @stable ICU 2.0
   1.260 +     */
   1.261 +    GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
   1.262 +
   1.263 +    /**
   1.264 +     * Constructs a GregorianCalendar with the given AD date and time set for the
   1.265 +     * default time zone with the default locale.
   1.266 +     *
   1.267 +     * @param year     The value used to set the YEAR time field in the calendar.
   1.268 +     * @param month    The value used to set the MONTH time field in the calendar. Month
   1.269 +     *                 value is 0-based. e.g., 0 for January.
   1.270 +     * @param date     The value used to set the DATE time field in the calendar.
   1.271 +     * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
   1.272 +     * @param minute   The value used to set the MINUTE time field in the calendar.
   1.273 +     * @param second   The value used to set the SECOND time field in the calendar.
   1.274 +     * @param success  Indicates the status of GregorianCalendar object construction.
   1.275 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.276 +     * @stable ICU 2.0
   1.277 +     */
   1.278 +    GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
   1.279 +
   1.280 +    /**
   1.281 +     * Destructor
   1.282 +     * @stable ICU 2.0
   1.283 +     */
   1.284 +    virtual ~GregorianCalendar();
   1.285 +
   1.286 +    /**
   1.287 +     * Copy constructor
   1.288 +     * @param source    the object to be copied.
   1.289 +     * @stable ICU 2.0
   1.290 +     */
   1.291 +    GregorianCalendar(const GregorianCalendar& source);
   1.292 +
   1.293 +    /**
   1.294 +     * Default assignment operator
   1.295 +     * @param right    the object to be copied.
   1.296 +     * @stable ICU 2.0
   1.297 +     */
   1.298 +    GregorianCalendar& operator=(const GregorianCalendar& right);
   1.299 +
   1.300 +    /**
   1.301 +     * Create and return a polymorphic copy of this calendar.
   1.302 +     * @return    return a polymorphic copy of this calendar.
   1.303 +     * @stable ICU 2.0
   1.304 +     */
   1.305 +    virtual Calendar* clone(void) const;
   1.306 +
   1.307 +    /**
   1.308 +     * Sets the GregorianCalendar change date. This is the point when the switch from
   1.309 +     * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
   1.310 +     * 15, 1582. Previous to this time and date will be Julian dates.
   1.311 +     *
   1.312 +     * @param date     The given Gregorian cutover date.
   1.313 +     * @param success  Output param set to success/failure code on exit.
   1.314 +     * @stable ICU 2.0
   1.315 +     */
   1.316 +    void setGregorianChange(UDate date, UErrorCode& success);
   1.317 +
   1.318 +    /**
   1.319 +     * Gets the Gregorian Calendar change date. This is the point when the switch from
   1.320 +     * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
   1.321 +     * 15, 1582. Previous to this time and date will be Julian dates.
   1.322 +     *
   1.323 +     * @return   The Gregorian cutover time for this calendar.
   1.324 +     * @stable ICU 2.0
   1.325 +     */
   1.326 +    UDate getGregorianChange(void) const;
   1.327 +
   1.328 +    /**
   1.329 +     * Return true if the given year is a leap year. Determination of whether a year is
   1.330 +     * a leap year is actually very complicated. We do something crude and mostly
   1.331 +     * correct here, but for a real determination you need a lot of contextual
   1.332 +     * information. For example, in Sweden, the change from Julian to Gregorian happened
   1.333 +     * in a complex way resulting in missed leap years and double leap years between
   1.334 +     * 1700 and 1753. Another example is that after the start of the Julian calendar in
   1.335 +     * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
   1.336 +     * quirks, and pays attention only to the Julian onset date and the Gregorian
   1.337 +     * cutover (which can be changed).
   1.338 +     *
   1.339 +     * @param year  The given year.
   1.340 +     * @return      True if the given year is a leap year; false otherwise.
   1.341 +     * @stable ICU 2.0
   1.342 +     */
   1.343 +    UBool isLeapYear(int32_t year) const;
   1.344 +
   1.345 +    /**
   1.346 +     * Returns TRUE if the given Calendar object is equivalent to this
   1.347 +     * one.  Calendar override.
   1.348 +     *
   1.349 +     * @param other the Calendar to be compared with this Calendar   
   1.350 +     * @stable ICU 2.4
   1.351 +     */
   1.352 +    virtual UBool isEquivalentTo(const Calendar& other) const;
   1.353 +
   1.354 +    /**
   1.355 +     * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
   1.356 +     * For more information, see the documentation for Calendar::roll().
   1.357 +     *
   1.358 +     * @param field   The time field.
   1.359 +     * @param amount  Indicates amount to roll.
   1.360 +     * @param status  Output param set to success/failure code on exit. If any value
   1.361 +     *                previously set in the time field is invalid, this will be set to
   1.362 +     *                an error status.
   1.363 +     * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
   1.364 +     */
   1.365 +    virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
   1.366 +
   1.367 +    /**
   1.368 +     * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
   1.369 +     * For more information, see the documentation for Calendar::roll().
   1.370 +     *
   1.371 +     * @param field   The time field.
   1.372 +     * @param amount  Indicates amount to roll.
   1.373 +     * @param status  Output param set to success/failure code on exit. If any value
   1.374 +     *                previously set in the time field is invalid, this will be set to
   1.375 +     *                an error status.
   1.376 +     * @stable ICU 2.6.
   1.377 +     */
   1.378 +    virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
   1.379 +
   1.380 +#ifndef U_HIDE_DEPRECATED_API
   1.381 +    /**
   1.382 +     * Return the minimum value that this field could have, given the current date.
   1.383 +     * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
   1.384 +     * @param field    the time field.
   1.385 +     * @return         the minimum value that this field could have, given the current date.
   1.386 +     * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
   1.387 +     */
   1.388 +    int32_t getActualMinimum(EDateFields field) const;
   1.389 +
   1.390 +    /**
   1.391 +     * Return the minimum value that this field could have, given the current date.
   1.392 +     * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
   1.393 +     * @param field    the time field.
   1.394 +     * @param status
   1.395 +     * @return         the minimum value that this field could have, given the current date.
   1.396 +     * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
   1.397 +     */
   1.398 +    int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
   1.399 +#endif  /* U_HIDE_DEPRECATED_API */
   1.400 +
   1.401 +    /**
   1.402 +     * Return the minimum value that this field could have, given the current date.
   1.403 +     * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
   1.404 +     * @param field    the time field.
   1.405 +     * @param status   error result.
   1.406 +     * @return         the minimum value that this field could have, given the current date.
   1.407 +     * @stable ICU 3.0
   1.408 +     */
   1.409 +    int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
   1.410 +
   1.411 +#ifndef U_HIDE_DEPRECATED_API
   1.412 +    /**
   1.413 +     * Return the maximum value that this field could have, given the current date.
   1.414 +     * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
   1.415 +     * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
   1.416 +     * for some years the actual maximum for MONTH is 12, and for others 13.
   1.417 +     * @param field    the time field.
   1.418 +     * @return         the maximum value that this field could have, given the current date.
   1.419 +     * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
   1.420 +     */
   1.421 +    int32_t getActualMaximum(EDateFields field) const;
   1.422 +#endif  /* U_HIDE_DEPRECATED_API */
   1.423 +
   1.424 +    /**
   1.425 +     * Return the maximum value that this field could have, given the current date.
   1.426 +     * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
   1.427 +     * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
   1.428 +     * for some years the actual maximum for MONTH is 12, and for others 13.
   1.429 +     * @param field    the time field.
   1.430 +     * @param status   returns any errors that may result from this function call.
   1.431 +     * @return         the maximum value that this field could have, given the current date.
   1.432 +     * @stable ICU 2.6
   1.433 +     */
   1.434 +    virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
   1.435 +
   1.436 +    /**
   1.437 +     * (Overrides Calendar) Return true if the current date for this Calendar is in
   1.438 +     * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
   1.439 +     *
   1.440 +     * @param status Fill-in parameter which receives the status of this operation.
   1.441 +     * @return   True if the current date for this Calendar is in Daylight Savings Time,
   1.442 +     *           false, otherwise.
   1.443 +     * @stable ICU 2.0
   1.444 +     */
   1.445 +    virtual UBool inDaylightTime(UErrorCode& status) const;
   1.446 +
   1.447 +public:
   1.448 +
   1.449 +    /**
   1.450 +     * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
   1.451 +     * override. This method is to implement a simple version of RTTI, since not all C++
   1.452 +     * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
   1.453 +     * this method.
   1.454 +     *
   1.455 +     * @return   The class ID for this object. All objects of a given class have the
   1.456 +     *           same class ID. Objects of other classes have different class IDs.
   1.457 +     * @stable ICU 2.0
   1.458 +     */
   1.459 +    virtual UClassID getDynamicClassID(void) const;
   1.460 +
   1.461 +    /**
   1.462 +     * Return the class ID for this class. This is useful only for comparing to a return
   1.463 +     * value from getDynamicClassID(). For example:
   1.464 +     *
   1.465 +     *      Base* polymorphic_pointer = createPolymorphicObject();
   1.466 +     *      if (polymorphic_pointer->getDynamicClassID() ==
   1.467 +     *          Derived::getStaticClassID()) ...
   1.468 +     *
   1.469 +     * @return   The class ID for all objects of this class.
   1.470 +     * @stable ICU 2.0
   1.471 +     */
   1.472 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.473 +
   1.474 +    /**
   1.475 +     * Returns the calendar type name string for this Calendar object.
   1.476 +     * The returned string is the legacy ICU calendar attribute value,
   1.477 +     * for example, "gregorian" or "japanese".
   1.478 +     *
   1.479 +     * For more details see the Calendar::getType() documentation.
   1.480 +     *
   1.481 +     * @return legacy calendar type name string
   1.482 +     * @stable ICU 49
   1.483 +     */
   1.484 +    virtual const char * getType() const;
   1.485 +
   1.486 + private:
   1.487 +    GregorianCalendar(); // default constructor not implemented
   1.488 +
   1.489 + protected:
   1.490 +    /**
   1.491 +     * Return the ERA.  We need a special method for this because the
   1.492 +     * default ERA is AD, but a zero (unset) ERA is BC.
   1.493 +     * @return    the ERA.
   1.494 +     * @internal
   1.495 +     */
   1.496 +    virtual int32_t internalGetEra() const;
   1.497 +
   1.498 +    /**
   1.499 +     * Return the Julian day number of day before the first day of the
   1.500 +     * given month in the given extended year.  Subclasses should override
   1.501 +     * this method to implement their calendar system.
   1.502 +     * @param eyear the extended year
   1.503 +     * @param month the zero-based month, or 0 if useMonth is false
   1.504 +     * @param useMonth if false, compute the day before the first day of
   1.505 +     * the given year, otherwise, compute the day before the first day of
   1.506 +     * the given month
   1.507 +     * @return the Julian day number of the day before the first
   1.508 +     * day of the given month and year
   1.509 +     * @internal
   1.510 +     */
   1.511 +    virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
   1.512 +                                                   UBool useMonth) const;
   1.513 +
   1.514 +    /**
   1.515 +     * Subclasses may override this.  This method calls
   1.516 +     * handleGetMonthLength() to obtain the calendar-specific month
   1.517 +     * length.
   1.518 +     * @param bestField which field to use to calculate the date 
   1.519 +     * @return julian day specified by calendar fields.
   1.520 +     * @internal
   1.521 +     */
   1.522 +    virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField)  ;
   1.523 +
   1.524 +    /**
   1.525 +     * Return the number of days in the given month of the given extended
   1.526 +     * year of this calendar system.  Subclasses should override this
   1.527 +     * method if they can provide a more correct or more efficient
   1.528 +     * implementation than the default implementation in Calendar.
   1.529 +     * @internal
   1.530 +     */
   1.531 +    virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
   1.532 +
   1.533 +    /**
   1.534 +     * Return the number of days in the given extended year of this
   1.535 +     * calendar system.  Subclasses should override this method if they can
   1.536 +     * provide a more correct or more efficient implementation than the
   1.537 +     * default implementation in Calendar.
   1.538 +     * @stable ICU 2.0
   1.539 +     */
   1.540 +    virtual int32_t handleGetYearLength(int32_t eyear) const;
   1.541 +
   1.542 +    /**
   1.543 +     * return the length of the given month.
   1.544 +     * @param month    the given month.
   1.545 +     * @return    the length of the given month.
   1.546 +     * @internal
   1.547 +     */
   1.548 +    virtual int32_t monthLength(int32_t month) const;
   1.549 +
   1.550 +    /**
   1.551 +     * return the length of the month according to the given year.
   1.552 +     * @param month    the given month.
   1.553 +     * @param year     the given year.
   1.554 +     * @return         the length of the month
   1.555 +     * @internal
   1.556 +     */
   1.557 +    virtual int32_t monthLength(int32_t month, int32_t year) const;
   1.558 +
   1.559 +#ifndef U_HIDE_INTERNAL_API
   1.560 +    /**
   1.561 +     * return the length of the given year.
   1.562 +     * @param year    the given year.
   1.563 +     * @return        the length of the given year.
   1.564 +     * @internal
   1.565 +     */
   1.566 +    int32_t yearLength(int32_t year) const;
   1.567 +    
   1.568 +    /**
   1.569 +     * return the length of the year field.
   1.570 +     * @return    the length of the year field
   1.571 +     * @internal
   1.572 +     */
   1.573 +    int32_t yearLength(void) const;
   1.574 +
   1.575 +    /**
   1.576 +     * After adjustments such as add(MONTH), add(YEAR), we don't want the
   1.577 +     * month to jump around.  E.g., we don't want Jan 31 + 1 month to go to Mar
   1.578 +     * 3, we want it to go to Feb 28.  Adjustments which might run into this
   1.579 +     * problem call this method to retain the proper month.
   1.580 +     * @internal
   1.581 +     */
   1.582 +    void pinDayOfMonth(void);
   1.583 +#endif  /* U_HIDE_INTERNAL_API */
   1.584 +
   1.585 +    /**
   1.586 +     * Return the day number with respect to the epoch.  January 1, 1970 (Gregorian)
   1.587 +     * is day zero.
   1.588 +     * @param status Fill-in parameter which receives the status of this operation.
   1.589 +     * @return       the day number with respect to the epoch.  
   1.590 +     * @internal
   1.591 +     */
   1.592 +    virtual UDate getEpochDay(UErrorCode& status);
   1.593 +
   1.594 +    /**
   1.595 +     * Subclass API for defining limits of different types.
   1.596 +     * Subclasses must implement this method to return limits for the
   1.597 +     * following fields:
   1.598 +     *
   1.599 +     * <pre>UCAL_ERA
   1.600 +     * UCAL_YEAR
   1.601 +     * UCAL_MONTH
   1.602 +     * UCAL_WEEK_OF_YEAR
   1.603 +     * UCAL_WEEK_OF_MONTH
   1.604 +     * UCAL_DATE (DAY_OF_MONTH on Java)
   1.605 +     * UCAL_DAY_OF_YEAR
   1.606 +     * UCAL_DAY_OF_WEEK_IN_MONTH
   1.607 +     * UCAL_YEAR_WOY
   1.608 +     * UCAL_EXTENDED_YEAR</pre>
   1.609 +     *
   1.610 +     * @param field one of the above field numbers
   1.611 +     * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
   1.612 +     * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
   1.613 +     * @internal
   1.614 +     */
   1.615 +    virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
   1.616 +
   1.617 +    /**
   1.618 +     * Return the extended year defined by the current fields.  This will
   1.619 +     * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
   1.620 +     * as UCAL_ERA) specific to the calendar system, depending on which set of
   1.621 +     * fields is newer.
   1.622 +     * @return the extended year
   1.623 +     * @internal
   1.624 +     */
   1.625 +    virtual int32_t handleGetExtendedYear();
   1.626 +
   1.627 +    /** 
   1.628 +     * Subclasses may override this to convert from week fields 
   1.629 +     * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
   1.630 +     * where YEAR, EXTENDED_YEAR are not set.
   1.631 +     * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
   1.632 +     * @return the extended year, UCAL_EXTENDED_YEAR
   1.633 +     * @internal
   1.634 +     */
   1.635 +    virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
   1.636 +
   1.637 +
   1.638 +    /**
   1.639 +     * Subclasses may override this method to compute several fields
   1.640 +     * specific to each calendar system.  These are:
   1.641 +     *
   1.642 +     * <ul><li>ERA
   1.643 +     * <li>YEAR
   1.644 +     * <li>MONTH
   1.645 +     * <li>DAY_OF_MONTH
   1.646 +     * <li>DAY_OF_YEAR
   1.647 +     * <li>EXTENDED_YEAR</ul>
   1.648 +     *
   1.649 +     * <p>The GregorianCalendar implementation implements
   1.650 +     * a calendar with the specified Julian/Gregorian cutover date.
   1.651 +     * @internal
   1.652 +     */
   1.653 +    virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
   1.654 +
   1.655 + private:
   1.656 +    /**
   1.657 +     * Compute the julian day number of the given year.
   1.658 +     * @param isGregorian    if true, using Gregorian calendar, otherwise using Julian calendar
   1.659 +     * @param year           the given year.
   1.660 +     * @param isLeap         true if the year is a leap year.       
   1.661 +     * @return 
   1.662 +     */
   1.663 +    static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
   1.664 +                                         UBool& isLeap);
   1.665 +    
   1.666 +    /**
   1.667 +     * Validates the values of the set time fields.  True if they're all valid.
   1.668 +     * @return    True if the set time fields are all valid.
   1.669 +     */
   1.670 +    UBool validateFields(void) const;
   1.671 +
   1.672 +    /**
   1.673 +     * Validates the value of the given time field.  True if it's valid.
   1.674 +     */
   1.675 +    UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
   1.676 +
   1.677 +    /**
   1.678 +     * Return the pseudo-time-stamp for two fields, given their
   1.679 +     * individual pseudo-time-stamps.  If either of the fields
   1.680 +     * is unset, then the aggregate is unset.  Otherwise, the
   1.681 +     * aggregate is the later of the two stamps.
   1.682 +     * @param stamp_a    One given field.
   1.683 +     * @param stamp_b    Another given field.
   1.684 +     * @return the pseudo-time-stamp for two fields
   1.685 +     */
   1.686 +    int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
   1.687 +
   1.688 +    /**
   1.689 +     * The point at which the Gregorian calendar rules are used, measured in
   1.690 +     * milliseconds from the standard epoch.  Default is October 15, 1582
   1.691 +     * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
   1.692 +     * by October 15, 1582 (Gregorian).  This corresponds to Julian day number
   1.693 +     * 2299161. This is measured from the standard epoch, not in Julian Days.
   1.694 +     */
   1.695 +    UDate                fGregorianCutover;
   1.696 +
   1.697 +    /**
   1.698 +     * Julian day number of the Gregorian cutover
   1.699 +     */
   1.700 +    int32_t             fCutoverJulianDay;
   1.701 +
   1.702 +    /**
   1.703 +     * Midnight, local time (using this Calendar's TimeZone) at or before the
   1.704 +     * gregorianCutover. This is a pure date value with no time of day or
   1.705 +     * timezone component.
   1.706 +     */
   1.707 +    UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
   1.708 +
   1.709 +    /**
   1.710 +     * The year of the gregorianCutover, with 0 representing
   1.711 +     * 1 BC, -1 representing 2 BC, etc.
   1.712 +     */
   1.713 +    int32_t fGregorianCutoverYear;// = 1582;
   1.714 +
   1.715 +    /**
   1.716 +     * The year of the gregorianCutover, with 0 representing
   1.717 +     * 1 BC, -1 representing 2 BC, etc.
   1.718 +     */
   1.719 +    int32_t fGregorianCutoverJulianDay;// = 2299161;
   1.720 +
   1.721 +    /**
   1.722 +     * Converts time as milliseconds to Julian date. The Julian date used here is not a
   1.723 +     * true Julian date, since it is measured from midnight, not noon.
   1.724 +     *
   1.725 +     * @param millis  The given milliseconds.
   1.726 +     * @return        The Julian date number.
   1.727 +     */
   1.728 +    static double millisToJulianDay(UDate millis);
   1.729 +
   1.730 +    /**
   1.731 +     * Converts Julian date to time as milliseconds. The Julian date used here is not a
   1.732 +     * true Julian date, since it is measured from midnight, not noon.
   1.733 +     *
   1.734 +     * @param julian  The given Julian date number.
   1.735 +     * @return        Time as milliseconds.
   1.736 +     */
   1.737 +    static UDate julianDayToMillis(double julian);
   1.738 +
   1.739 +    /**
   1.740 +     * Used by handleComputeJulianDay() and handleComputeMonthStart().
   1.741 +     * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
   1.742 +     */
   1.743 +    UBool fIsGregorian;
   1.744 +
   1.745 +    /**
   1.746 +     * Used by handleComputeJulianDay() and handleComputeMonthStart().
   1.747 +     * Temporary field indicating that the sense of the gregorian cutover should be inverted
   1.748 +     * to handle certain calculations on and around the cutover date.
   1.749 +     */
   1.750 +    UBool fInvertGregorian;
   1.751 +
   1.752 +
   1.753 + public: // internal implementation
   1.754 +
   1.755 +    /**
   1.756 +     * @return TRUE if this calendar has the notion of a default century
   1.757 +     * @internal 
   1.758 +     */
   1.759 +    virtual UBool haveDefaultCentury() const;
   1.760 +
   1.761 +    /**
   1.762 +     * @return the start of the default century
   1.763 +     * @internal
   1.764 +     */
   1.765 +    virtual UDate defaultCenturyStart() const;
   1.766 +
   1.767 +    /**
   1.768 +     * @return the beginning year of the default century
   1.769 +     * @internal 
   1.770 +     */
   1.771 +    virtual int32_t defaultCenturyStartYear() const;
   1.772 +};
   1.773 +
   1.774 +U_NAMESPACE_END
   1.775 +
   1.776 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.777 +
   1.778 +#endif // _GREGOCAL
   1.779 +//eof
   1.780 +

mercurial