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