annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/gregocal.h @ 69:33d812a61356

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