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