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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
michael@0 3 * All Rights Reserved.
michael@0 4 ********************************************************************************
michael@0 5 *
michael@0 6 * File GREGOCAL.H
michael@0 7 *
michael@0 8 * Modification History:
michael@0 9 *
michael@0 10 * Date Name Description
michael@0 11 * 04/22/97 aliu Overhauled header.
michael@0 12 * 07/28/98 stephen Sync with JDK 1.2
michael@0 13 * 09/04/98 stephen Re-sync with JDK 8/31 putback
michael@0 14 * 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
michael@0 15 * Fixed bug in roll()
michael@0 16 * 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
michael@0 17 * Added documentation of WEEK_OF_YEAR computation.
michael@0 18 * 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
michael@0 19 * {JDK bug 4210209 4209272}
michael@0 20 * 11/07/2003 srl Update, clean up documentation.
michael@0 21 ********************************************************************************
michael@0 22 */
michael@0 23
michael@0 24 #ifndef GREGOCAL_H
michael@0 25 #define GREGOCAL_H
michael@0 26
michael@0 27 #include "unicode/utypes.h"
michael@0 28
michael@0 29 #if !UCONFIG_NO_FORMATTING
michael@0 30
michael@0 31 #include "unicode/calendar.h"
michael@0 32
michael@0 33 /**
michael@0 34 * \file
michael@0 35 * \brief C++ API: Concrete class which provides the standard calendar.
michael@0 36 */
michael@0 37
michael@0 38 U_NAMESPACE_BEGIN
michael@0 39
michael@0 40 /**
michael@0 41 * Concrete class which provides the standard calendar used by most of the world.
michael@0 42 * <P>
michael@0 43 * The standard (Gregorian) calendar has 2 eras, BC and AD.
michael@0 44 * <P>
michael@0 45 * This implementation handles a single discontinuity, which corresponds by default to
michael@0 46 * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
michael@0 47 * countries adopted the Gregorian calendar then, so this cutover date may be changed by
michael@0 48 * the caller.
michael@0 49 * <P>
michael@0 50 * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
michael@0 51 * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
michael@0 52 * if desired for dates that are prior to the Gregorian changeover and which fall
michael@0 53 * between January 1 and March 24.
michael@0 54 *
michael@0 55 * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
michael@0 56 * 53. Week 1 for a year is the first week that contains at least
michael@0 57 * <code>getMinimalDaysInFirstWeek()</code> days from that year. It thus
michael@0 58 * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
michael@0 59 * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
michael@0 60 * Weeks between week 1 of one year and week 1 of the following year are
michael@0 61 * numbered sequentially from 2 to 52 or 53 (as needed).
michael@0 62 *
michael@0 63 * <p>For example, January 1, 1998 was a Thursday. If
michael@0 64 * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
michael@0 65 * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
michael@0 66 * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
michael@0 67 * on December 29, 1997, and ends on January 4, 1998. If, however,
michael@0 68 * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
michael@0 69 * starts on January 4, 1998, and ends on January 10, 1998; the first three days
michael@0 70 * of 1998 then are part of week 53 of 1997.
michael@0 71 *
michael@0 72 * <p>Example for using GregorianCalendar:
michael@0 73 * <pre>
michael@0 74 * \code
michael@0 75 * // get the supported ids for GMT-08:00 (Pacific Standard Time)
michael@0 76 * UErrorCode success = U_ZERO_ERROR;
michael@0 77 * const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
michael@0 78 * // if no ids were returned, something is wrong. get out.
michael@0 79 * if (ids == 0 || ids->count(success) == 0) {
michael@0 80 * return;
michael@0 81 * }
michael@0 82 *
michael@0 83 * // begin output
michael@0 84 * cout << "Current Time" << endl;
michael@0 85 *
michael@0 86 * // create a Pacific Standard Time time zone
michael@0 87 * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));
michael@0 88 *
michael@0 89 * // set up rules for daylight savings time
michael@0 90 * pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
michael@0 91 * pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
michael@0 92 *
michael@0 93 * // create a GregorianCalendar with the Pacific Daylight time zone
michael@0 94 * // and the current date and time
michael@0 95 * Calendar* calendar = new GregorianCalendar( pdt, success );
michael@0 96 *
michael@0 97 * // print out a bunch of interesting things
michael@0 98 * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
michael@0 99 * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
michael@0 100 * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
michael@0 101 * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
michael@0 102 * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
michael@0 103 * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
michael@0 104 * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
michael@0 105 * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
michael@0 106 * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
michael@0 107 * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
michael@0 108 * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
michael@0 109 * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
michael@0 110 * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
michael@0 111 * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
michael@0 112 * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
michael@0 113 * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
michael@0 114 * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
michael@0 115 * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
michael@0 116 *
michael@0 117 * cout << "Current Time, with hour reset to 3" << endl;
michael@0 118 * calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
michael@0 119 * calendar->set(UCAL_HOUR, 3);
michael@0 120 * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
michael@0 121 * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
michael@0 122 * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
michael@0 123 * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
michael@0 124 * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
michael@0 125 * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
michael@0 126 * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
michael@0 127 * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
michael@0 128 * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
michael@0 129 * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
michael@0 130 * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
michael@0 131 * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
michael@0 132 * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
michael@0 133 * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
michael@0 134 * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
michael@0 135 * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
michael@0 136 * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
michael@0 137 * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
michael@0 138 *
michael@0 139 * if (U_FAILURE(success)) {
michael@0 140 * cout << "An error occured. success=" << u_errorName(success) << endl;
michael@0 141 * }
michael@0 142 *
michael@0 143 * delete ids;
michael@0 144 * delete calendar; // also deletes pdt
michael@0 145 * \endcode
michael@0 146 * </pre>
michael@0 147 * @stable ICU 2.0
michael@0 148 */
michael@0 149 class U_I18N_API GregorianCalendar: public Calendar {
michael@0 150 public:
michael@0 151
michael@0 152 /**
michael@0 153 * Useful constants for GregorianCalendar and TimeZone.
michael@0 154 * @stable ICU 2.0
michael@0 155 */
michael@0 156 enum EEras {
michael@0 157 BC,
michael@0 158 AD
michael@0 159 };
michael@0 160
michael@0 161 /**
michael@0 162 * Constructs a default GregorianCalendar using the current time in the default time
michael@0 163 * zone with the default locale.
michael@0 164 *
michael@0 165 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 166 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 167 * @stable ICU 2.0
michael@0 168 */
michael@0 169 GregorianCalendar(UErrorCode& success);
michael@0 170
michael@0 171 /**
michael@0 172 * Constructs a GregorianCalendar based on the current time in the given time zone
michael@0 173 * with the default locale. Clients are no longer responsible for deleting the given
michael@0 174 * time zone object after it's adopted.
michael@0 175 *
michael@0 176 * @param zoneToAdopt The given timezone.
michael@0 177 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 178 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 179 * @stable ICU 2.0
michael@0 180 */
michael@0 181 GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
michael@0 182
michael@0 183 /**
michael@0 184 * Constructs a GregorianCalendar based on the current time in the given time zone
michael@0 185 * with the default locale.
michael@0 186 *
michael@0 187 * @param zone The given timezone.
michael@0 188 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 189 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 190 * @stable ICU 2.0
michael@0 191 */
michael@0 192 GregorianCalendar(const TimeZone& zone, UErrorCode& success);
michael@0 193
michael@0 194 /**
michael@0 195 * Constructs a GregorianCalendar based on the current time in the default time zone
michael@0 196 * with the given locale.
michael@0 197 *
michael@0 198 * @param aLocale The given locale.
michael@0 199 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 200 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 201 * @stable ICU 2.0
michael@0 202 */
michael@0 203 GregorianCalendar(const Locale& aLocale, UErrorCode& success);
michael@0 204
michael@0 205 /**
michael@0 206 * Constructs a GregorianCalendar based on the current time in the given time zone
michael@0 207 * with the given locale. Clients are no longer responsible for deleting the given
michael@0 208 * time zone object after it's adopted.
michael@0 209 *
michael@0 210 * @param zoneToAdopt The given timezone.
michael@0 211 * @param aLocale The given locale.
michael@0 212 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 213 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 214 * @stable ICU 2.0
michael@0 215 */
michael@0 216 GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
michael@0 217
michael@0 218 /**
michael@0 219 * Constructs a GregorianCalendar based on the current time in the given time zone
michael@0 220 * with the given locale.
michael@0 221 *
michael@0 222 * @param zone The given timezone.
michael@0 223 * @param aLocale The given locale.
michael@0 224 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 225 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 226 * @stable ICU 2.0
michael@0 227 */
michael@0 228 GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
michael@0 229
michael@0 230 /**
michael@0 231 * Constructs a GregorianCalendar with the given AD date set in the default time
michael@0 232 * zone with the default locale.
michael@0 233 *
michael@0 234 * @param year The value used to set the YEAR time field in the calendar.
michael@0 235 * @param month The value used to set the MONTH time field in the calendar. Month
michael@0 236 * value is 0-based. e.g., 0 for January.
michael@0 237 * @param date The value used to set the DATE time field in the calendar.
michael@0 238 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 239 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 240 * @stable ICU 2.0
michael@0 241 */
michael@0 242 GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
michael@0 243
michael@0 244 /**
michael@0 245 * Constructs a GregorianCalendar with the given AD date and time set for the
michael@0 246 * default time zone with the default locale.
michael@0 247 *
michael@0 248 * @param year The value used to set the YEAR time field in the calendar.
michael@0 249 * @param month The value used to set the MONTH time field in the calendar. Month
michael@0 250 * value is 0-based. e.g., 0 for January.
michael@0 251 * @param date The value used to set the DATE time field in the calendar.
michael@0 252 * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
michael@0 253 * @param minute The value used to set the MINUTE time field in the calendar.
michael@0 254 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 255 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 256 * @stable ICU 2.0
michael@0 257 */
michael@0 258 GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
michael@0 259
michael@0 260 /**
michael@0 261 * Constructs a GregorianCalendar with the given AD date and time set for the
michael@0 262 * default time zone with the default locale.
michael@0 263 *
michael@0 264 * @param year The value used to set the YEAR time field in the calendar.
michael@0 265 * @param month The value used to set the MONTH time field in the calendar. Month
michael@0 266 * value is 0-based. e.g., 0 for January.
michael@0 267 * @param date The value used to set the DATE time field in the calendar.
michael@0 268 * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
michael@0 269 * @param minute The value used to set the MINUTE time field in the calendar.
michael@0 270 * @param second The value used to set the SECOND time field in the calendar.
michael@0 271 * @param success Indicates the status of GregorianCalendar object construction.
michael@0 272 * Returns U_ZERO_ERROR if constructed successfully.
michael@0 273 * @stable ICU 2.0
michael@0 274 */
michael@0 275 GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
michael@0 276
michael@0 277 /**
michael@0 278 * Destructor
michael@0 279 * @stable ICU 2.0
michael@0 280 */
michael@0 281 virtual ~GregorianCalendar();
michael@0 282
michael@0 283 /**
michael@0 284 * Copy constructor
michael@0 285 * @param source the object to be copied.
michael@0 286 * @stable ICU 2.0
michael@0 287 */
michael@0 288 GregorianCalendar(const GregorianCalendar& source);
michael@0 289
michael@0 290 /**
michael@0 291 * Default assignment operator
michael@0 292 * @param right the object to be copied.
michael@0 293 * @stable ICU 2.0
michael@0 294 */
michael@0 295 GregorianCalendar& operator=(const GregorianCalendar& right);
michael@0 296
michael@0 297 /**
michael@0 298 * Create and return a polymorphic copy of this calendar.
michael@0 299 * @return return a polymorphic copy of this calendar.
michael@0 300 * @stable ICU 2.0
michael@0 301 */
michael@0 302 virtual Calendar* clone(void) const;
michael@0 303
michael@0 304 /**
michael@0 305 * Sets the GregorianCalendar change date. This is the point when the switch from
michael@0 306 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
michael@0 307 * 15, 1582. Previous to this time and date will be Julian dates.
michael@0 308 *
michael@0 309 * @param date The given Gregorian cutover date.
michael@0 310 * @param success Output param set to success/failure code on exit.
michael@0 311 * @stable ICU 2.0
michael@0 312 */
michael@0 313 void setGregorianChange(UDate date, UErrorCode& success);
michael@0 314
michael@0 315 /**
michael@0 316 * Gets the Gregorian Calendar change date. This is the point when the switch from
michael@0 317 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
michael@0 318 * 15, 1582. Previous to this time and date will be Julian dates.
michael@0 319 *
michael@0 320 * @return The Gregorian cutover time for this calendar.
michael@0 321 * @stable ICU 2.0
michael@0 322 */
michael@0 323 UDate getGregorianChange(void) const;
michael@0 324
michael@0 325 /**
michael@0 326 * Return true if the given year is a leap year. Determination of whether a year is
michael@0 327 * a leap year is actually very complicated. We do something crude and mostly
michael@0 328 * correct here, but for a real determination you need a lot of contextual
michael@0 329 * information. For example, in Sweden, the change from Julian to Gregorian happened
michael@0 330 * in a complex way resulting in missed leap years and double leap years between
michael@0 331 * 1700 and 1753. Another example is that after the start of the Julian calendar in
michael@0 332 * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
michael@0 333 * quirks, and pays attention only to the Julian onset date and the Gregorian
michael@0 334 * cutover (which can be changed).
michael@0 335 *
michael@0 336 * @param year The given year.
michael@0 337 * @return True if the given year is a leap year; false otherwise.
michael@0 338 * @stable ICU 2.0
michael@0 339 */
michael@0 340 UBool isLeapYear(int32_t year) const;
michael@0 341
michael@0 342 /**
michael@0 343 * Returns TRUE if the given Calendar object is equivalent to this
michael@0 344 * one. Calendar override.
michael@0 345 *
michael@0 346 * @param other the Calendar to be compared with this Calendar
michael@0 347 * @stable ICU 2.4
michael@0 348 */
michael@0 349 virtual UBool isEquivalentTo(const Calendar& other) const;
michael@0 350
michael@0 351 /**
michael@0 352 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
michael@0 353 * For more information, see the documentation for Calendar::roll().
michael@0 354 *
michael@0 355 * @param field The time field.
michael@0 356 * @param amount Indicates amount to roll.
michael@0 357 * @param status Output param set to success/failure code on exit. If any value
michael@0 358 * previously set in the time field is invalid, this will be set to
michael@0 359 * an error status.
michael@0 360 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
michael@0 361 */
michael@0 362 virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
michael@0 363
michael@0 364 /**
michael@0 365 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
michael@0 366 * For more information, see the documentation for Calendar::roll().
michael@0 367 *
michael@0 368 * @param field The time field.
michael@0 369 * @param amount Indicates amount to roll.
michael@0 370 * @param status Output param set to success/failure code on exit. If any value
michael@0 371 * previously set in the time field is invalid, this will be set to
michael@0 372 * an error status.
michael@0 373 * @stable ICU 2.6.
michael@0 374 */
michael@0 375 virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
michael@0 376
michael@0 377 #ifndef U_HIDE_DEPRECATED_API
michael@0 378 /**
michael@0 379 * Return the minimum value that this field could have, given the current date.
michael@0 380 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
michael@0 381 * @param field the time field.
michael@0 382 * @return the minimum value that this field could have, given the current date.
michael@0 383 * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
michael@0 384 */
michael@0 385 int32_t getActualMinimum(EDateFields field) const;
michael@0 386
michael@0 387 /**
michael@0 388 * Return the minimum value that this field could have, given the current date.
michael@0 389 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
michael@0 390 * @param field the time field.
michael@0 391 * @param status
michael@0 392 * @return the minimum value that this field could have, given the current date.
michael@0 393 * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
michael@0 394 */
michael@0 395 int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
michael@0 396 #endif /* U_HIDE_DEPRECATED_API */
michael@0 397
michael@0 398 /**
michael@0 399 * Return the minimum value that this field could have, given the current date.
michael@0 400 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
michael@0 401 * @param field the time field.
michael@0 402 * @param status error result.
michael@0 403 * @return the minimum value that this field could have, given the current date.
michael@0 404 * @stable ICU 3.0
michael@0 405 */
michael@0 406 int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const;
michael@0 407
michael@0 408 #ifndef U_HIDE_DEPRECATED_API
michael@0 409 /**
michael@0 410 * Return the maximum value that this field could have, given the current date.
michael@0 411 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
michael@0 412 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
michael@0 413 * for some years the actual maximum for MONTH is 12, and for others 13.
michael@0 414 * @param field the time field.
michael@0 415 * @return the maximum value that this field could have, given the current date.
michael@0 416 * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
michael@0 417 */
michael@0 418 int32_t getActualMaximum(EDateFields field) const;
michael@0 419 #endif /* U_HIDE_DEPRECATED_API */
michael@0 420
michael@0 421 /**
michael@0 422 * Return the maximum value that this field could have, given the current date.
michael@0 423 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
michael@0 424 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
michael@0 425 * for some years the actual maximum for MONTH is 12, and for others 13.
michael@0 426 * @param field the time field.
michael@0 427 * @param status returns any errors that may result from this function call.
michael@0 428 * @return the maximum value that this field could have, given the current date.
michael@0 429 * @stable ICU 2.6
michael@0 430 */
michael@0 431 virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
michael@0 432
michael@0 433 /**
michael@0 434 * (Overrides Calendar) Return true if the current date for this Calendar is in
michael@0 435 * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
michael@0 436 *
michael@0 437 * @param status Fill-in parameter which receives the status of this operation.
michael@0 438 * @return True if the current date for this Calendar is in Daylight Savings Time,
michael@0 439 * false, otherwise.
michael@0 440 * @stable ICU 2.0
michael@0 441 */
michael@0 442 virtual UBool inDaylightTime(UErrorCode& status) const;
michael@0 443
michael@0 444 public:
michael@0 445
michael@0 446 /**
michael@0 447 * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
michael@0 448 * override. This method is to implement a simple version of RTTI, since not all C++
michael@0 449 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
michael@0 450 * this method.
michael@0 451 *
michael@0 452 * @return The class ID for this object. All objects of a given class have the
michael@0 453 * same class ID. Objects of other classes have different class IDs.
michael@0 454 * @stable ICU 2.0
michael@0 455 */
michael@0 456 virtual UClassID getDynamicClassID(void) const;
michael@0 457
michael@0 458 /**
michael@0 459 * Return the class ID for this class. This is useful only for comparing to a return
michael@0 460 * value from getDynamicClassID(). For example:
michael@0 461 *
michael@0 462 * Base* polymorphic_pointer = createPolymorphicObject();
michael@0 463 * if (polymorphic_pointer->getDynamicClassID() ==
michael@0 464 * Derived::getStaticClassID()) ...
michael@0 465 *
michael@0 466 * @return The class ID for all objects of this class.
michael@0 467 * @stable ICU 2.0
michael@0 468 */
michael@0 469 static UClassID U_EXPORT2 getStaticClassID(void);
michael@0 470
michael@0 471 /**
michael@0 472 * Returns the calendar type name string for this Calendar object.
michael@0 473 * The returned string is the legacy ICU calendar attribute value,
michael@0 474 * for example, "gregorian" or "japanese".
michael@0 475 *
michael@0 476 * For more details see the Calendar::getType() documentation.
michael@0 477 *
michael@0 478 * @return legacy calendar type name string
michael@0 479 * @stable ICU 49
michael@0 480 */
michael@0 481 virtual const char * getType() const;
michael@0 482
michael@0 483 private:
michael@0 484 GregorianCalendar(); // default constructor not implemented
michael@0 485
michael@0 486 protected:
michael@0 487 /**
michael@0 488 * Return the ERA. We need a special method for this because the
michael@0 489 * default ERA is AD, but a zero (unset) ERA is BC.
michael@0 490 * @return the ERA.
michael@0 491 * @internal
michael@0 492 */
michael@0 493 virtual int32_t internalGetEra() const;
michael@0 494
michael@0 495 /**
michael@0 496 * Return the Julian day number of day before the first day of the
michael@0 497 * given month in the given extended year. Subclasses should override
michael@0 498 * this method to implement their calendar system.
michael@0 499 * @param eyear the extended year
michael@0 500 * @param month the zero-based month, or 0 if useMonth is false
michael@0 501 * @param useMonth if false, compute the day before the first day of
michael@0 502 * the given year, otherwise, compute the day before the first day of
michael@0 503 * the given month
michael@0 504 * @return the Julian day number of the day before the first
michael@0 505 * day of the given month and year
michael@0 506 * @internal
michael@0 507 */
michael@0 508 virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
michael@0 509 UBool useMonth) const;
michael@0 510
michael@0 511 /**
michael@0 512 * Subclasses may override this. This method calls
michael@0 513 * handleGetMonthLength() to obtain the calendar-specific month
michael@0 514 * length.
michael@0 515 * @param bestField which field to use to calculate the date
michael@0 516 * @return julian day specified by calendar fields.
michael@0 517 * @internal
michael@0 518 */
michael@0 519 virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
michael@0 520
michael@0 521 /**
michael@0 522 * Return the number of days in the given month of the given extended
michael@0 523 * year of this calendar system. Subclasses should override this
michael@0 524 * method if they can provide a more correct or more efficient
michael@0 525 * implementation than the default implementation in Calendar.
michael@0 526 * @internal
michael@0 527 */
michael@0 528 virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
michael@0 529
michael@0 530 /**
michael@0 531 * Return the number of days in the given extended year of this
michael@0 532 * calendar system. Subclasses should override this method if they can
michael@0 533 * provide a more correct or more efficient implementation than the
michael@0 534 * default implementation in Calendar.
michael@0 535 * @stable ICU 2.0
michael@0 536 */
michael@0 537 virtual int32_t handleGetYearLength(int32_t eyear) const;
michael@0 538
michael@0 539 /**
michael@0 540 * return the length of the given month.
michael@0 541 * @param month the given month.
michael@0 542 * @return the length of the given month.
michael@0 543 * @internal
michael@0 544 */
michael@0 545 virtual int32_t monthLength(int32_t month) const;
michael@0 546
michael@0 547 /**
michael@0 548 * return the length of the month according to the given year.
michael@0 549 * @param month the given month.
michael@0 550 * @param year the given year.
michael@0 551 * @return the length of the month
michael@0 552 * @internal
michael@0 553 */
michael@0 554 virtual int32_t monthLength(int32_t month, int32_t year) const;
michael@0 555
michael@0 556 #ifndef U_HIDE_INTERNAL_API
michael@0 557 /**
michael@0 558 * return the length of the given year.
michael@0 559 * @param year the given year.
michael@0 560 * @return the length of the given year.
michael@0 561 * @internal
michael@0 562 */
michael@0 563 int32_t yearLength(int32_t year) const;
michael@0 564
michael@0 565 /**
michael@0 566 * return the length of the year field.
michael@0 567 * @return the length of the year field
michael@0 568 * @internal
michael@0 569 */
michael@0 570 int32_t yearLength(void) const;
michael@0 571
michael@0 572 /**
michael@0 573 * After adjustments such as add(MONTH), add(YEAR), we don't want the
michael@0 574 * month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar
michael@0 575 * 3, we want it to go to Feb 28. Adjustments which might run into this
michael@0 576 * problem call this method to retain the proper month.
michael@0 577 * @internal
michael@0 578 */
michael@0 579 void pinDayOfMonth(void);
michael@0 580 #endif /* U_HIDE_INTERNAL_API */
michael@0 581
michael@0 582 /**
michael@0 583 * Return the day number with respect to the epoch. January 1, 1970 (Gregorian)
michael@0 584 * is day zero.
michael@0 585 * @param status Fill-in parameter which receives the status of this operation.
michael@0 586 * @return the day number with respect to the epoch.
michael@0 587 * @internal
michael@0 588 */
michael@0 589 virtual UDate getEpochDay(UErrorCode& status);
michael@0 590
michael@0 591 /**
michael@0 592 * Subclass API for defining limits of different types.
michael@0 593 * Subclasses must implement this method to return limits for the
michael@0 594 * following fields:
michael@0 595 *
michael@0 596 * <pre>UCAL_ERA
michael@0 597 * UCAL_YEAR
michael@0 598 * UCAL_MONTH
michael@0 599 * UCAL_WEEK_OF_YEAR
michael@0 600 * UCAL_WEEK_OF_MONTH
michael@0 601 * UCAL_DATE (DAY_OF_MONTH on Java)
michael@0 602 * UCAL_DAY_OF_YEAR
michael@0 603 * UCAL_DAY_OF_WEEK_IN_MONTH
michael@0 604 * UCAL_YEAR_WOY
michael@0 605 * UCAL_EXTENDED_YEAR</pre>
michael@0 606 *
michael@0 607 * @param field one of the above field numbers
michael@0 608 * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
michael@0 609 * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
michael@0 610 * @internal
michael@0 611 */
michael@0 612 virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
michael@0 613
michael@0 614 /**
michael@0 615 * Return the extended year defined by the current fields. This will
michael@0 616 * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
michael@0 617 * as UCAL_ERA) specific to the calendar system, depending on which set of
michael@0 618 * fields is newer.
michael@0 619 * @return the extended year
michael@0 620 * @internal
michael@0 621 */
michael@0 622 virtual int32_t handleGetExtendedYear();
michael@0 623
michael@0 624 /**
michael@0 625 * Subclasses may override this to convert from week fields
michael@0 626 * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
michael@0 627 * where YEAR, EXTENDED_YEAR are not set.
michael@0 628 * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
michael@0 629 * @return the extended year, UCAL_EXTENDED_YEAR
michael@0 630 * @internal
michael@0 631 */
michael@0 632 virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
michael@0 633
michael@0 634
michael@0 635 /**
michael@0 636 * Subclasses may override this method to compute several fields
michael@0 637 * specific to each calendar system. These are:
michael@0 638 *
michael@0 639 * <ul><li>ERA
michael@0 640 * <li>YEAR
michael@0 641 * <li>MONTH
michael@0 642 * <li>DAY_OF_MONTH
michael@0 643 * <li>DAY_OF_YEAR
michael@0 644 * <li>EXTENDED_YEAR</ul>
michael@0 645 *
michael@0 646 * <p>The GregorianCalendar implementation implements
michael@0 647 * a calendar with the specified Julian/Gregorian cutover date.
michael@0 648 * @internal
michael@0 649 */
michael@0 650 virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
michael@0 651
michael@0 652 private:
michael@0 653 /**
michael@0 654 * Compute the julian day number of the given year.
michael@0 655 * @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar
michael@0 656 * @param year the given year.
michael@0 657 * @param isLeap true if the year is a leap year.
michael@0 658 * @return
michael@0 659 */
michael@0 660 static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
michael@0 661 UBool& isLeap);
michael@0 662
michael@0 663 /**
michael@0 664 * Validates the values of the set time fields. True if they're all valid.
michael@0 665 * @return True if the set time fields are all valid.
michael@0 666 */
michael@0 667 UBool validateFields(void) const;
michael@0 668
michael@0 669 /**
michael@0 670 * Validates the value of the given time field. True if it's valid.
michael@0 671 */
michael@0 672 UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
michael@0 673
michael@0 674 /**
michael@0 675 * Return the pseudo-time-stamp for two fields, given their
michael@0 676 * individual pseudo-time-stamps. If either of the fields
michael@0 677 * is unset, then the aggregate is unset. Otherwise, the
michael@0 678 * aggregate is the later of the two stamps.
michael@0 679 * @param stamp_a One given field.
michael@0 680 * @param stamp_b Another given field.
michael@0 681 * @return the pseudo-time-stamp for two fields
michael@0 682 */
michael@0 683 int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
michael@0 684
michael@0 685 /**
michael@0 686 * The point at which the Gregorian calendar rules are used, measured in
michael@0 687 * milliseconds from the standard epoch. Default is October 15, 1582
michael@0 688 * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
michael@0 689 * by October 15, 1582 (Gregorian). This corresponds to Julian day number
michael@0 690 * 2299161. This is measured from the standard epoch, not in Julian Days.
michael@0 691 */
michael@0 692 UDate fGregorianCutover;
michael@0 693
michael@0 694 /**
michael@0 695 * Julian day number of the Gregorian cutover
michael@0 696 */
michael@0 697 int32_t fCutoverJulianDay;
michael@0 698
michael@0 699 /**
michael@0 700 * Midnight, local time (using this Calendar's TimeZone) at or before the
michael@0 701 * gregorianCutover. This is a pure date value with no time of day or
michael@0 702 * timezone component.
michael@0 703 */
michael@0 704 UDate fNormalizedGregorianCutover;// = gregorianCutover;
michael@0 705
michael@0 706 /**
michael@0 707 * The year of the gregorianCutover, with 0 representing
michael@0 708 * 1 BC, -1 representing 2 BC, etc.
michael@0 709 */
michael@0 710 int32_t fGregorianCutoverYear;// = 1582;
michael@0 711
michael@0 712 /**
michael@0 713 * The year of the gregorianCutover, with 0 representing
michael@0 714 * 1 BC, -1 representing 2 BC, etc.
michael@0 715 */
michael@0 716 int32_t fGregorianCutoverJulianDay;// = 2299161;
michael@0 717
michael@0 718 /**
michael@0 719 * Converts time as milliseconds to Julian date. The Julian date used here is not a
michael@0 720 * true Julian date, since it is measured from midnight, not noon.
michael@0 721 *
michael@0 722 * @param millis The given milliseconds.
michael@0 723 * @return The Julian date number.
michael@0 724 */
michael@0 725 static double millisToJulianDay(UDate millis);
michael@0 726
michael@0 727 /**
michael@0 728 * Converts Julian date to time as milliseconds. The Julian date used here is not a
michael@0 729 * true Julian date, since it is measured from midnight, not noon.
michael@0 730 *
michael@0 731 * @param julian The given Julian date number.
michael@0 732 * @return Time as milliseconds.
michael@0 733 */
michael@0 734 static UDate julianDayToMillis(double julian);
michael@0 735
michael@0 736 /**
michael@0 737 * Used by handleComputeJulianDay() and handleComputeMonthStart().
michael@0 738 * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
michael@0 739 */
michael@0 740 UBool fIsGregorian;
michael@0 741
michael@0 742 /**
michael@0 743 * Used by handleComputeJulianDay() and handleComputeMonthStart().
michael@0 744 * Temporary field indicating that the sense of the gregorian cutover should be inverted
michael@0 745 * to handle certain calculations on and around the cutover date.
michael@0 746 */
michael@0 747 UBool fInvertGregorian;
michael@0 748
michael@0 749
michael@0 750 public: // internal implementation
michael@0 751
michael@0 752 /**
michael@0 753 * @return TRUE if this calendar has the notion of a default century
michael@0 754 * @internal
michael@0 755 */
michael@0 756 virtual UBool haveDefaultCentury() const;
michael@0 757
michael@0 758 /**
michael@0 759 * @return the start of the default century
michael@0 760 * @internal
michael@0 761 */
michael@0 762 virtual UDate defaultCenturyStart() const;
michael@0 763
michael@0 764 /**
michael@0 765 * @return the beginning year of the default century
michael@0 766 * @internal
michael@0 767 */
michael@0 768 virtual int32_t defaultCenturyStartYear() const;
michael@0 769 };
michael@0 770
michael@0 771 U_NAMESPACE_END
michael@0 772
michael@0 773 #endif /* #if !UCONFIG_NO_FORMATTING */
michael@0 774
michael@0 775 #endif // _GREGOCAL
michael@0 776 //eof
michael@0 777

mercurial