Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | /* |
374ca955 A |
2 | * Copyright (C) 2003-2004, International Business Machines Corporation |
3 | * and others. All Rights Reserved. | |
4 | ******************************************************************************** | |
5 | * | |
6 | * File BUDDHCAL.H | |
7 | * | |
8 | * Modification History: | |
9 | * | |
10 | * Date Name Description | |
11 | * 05/13/2003 srl copied from gregocal.h | |
12 | ******************************************************************************** | |
13 | */ | |
b75a7d8f A |
14 | |
15 | #ifndef BUDDHCAL_H | |
16 | #define BUDDHCAL_H | |
17 | ||
18 | #include "unicode/utypes.h" | |
19 | ||
20 | #if !UCONFIG_NO_FORMATTING | |
21 | ||
22 | #include "unicode/calendar.h" | |
23 | #include "unicode/gregocal.h" | |
24 | ||
25 | U_NAMESPACE_BEGIN | |
26 | ||
27 | /** | |
28 | * Concrete class which provides the Buddhist calendar. | |
29 | * <P> | |
30 | * <code>BuddhistCalendar</code> is a subclass of <code>GregorianCalendar</code> | |
31 | * that numbers years since the birth of the Buddha. This is the civil calendar | |
32 | * in some predominantly Buddhist countries such as Thailand, and it is used for | |
33 | * religious purposes elsewhere. | |
34 | * <p> | |
35 | * The Buddhist calendar is identical to the Gregorian calendar in all respects | |
36 | * except for the year and era. Years are numbered since the birth of the | |
37 | * Buddha in 543 BC (Gregorian), so that 1 AD (Gregorian) is equivalent to 544 | |
38 | * BE (Buddhist Era) and 1998 AD is 2541 BE. | |
39 | * <p> | |
40 | * The Buddhist Calendar has only one allowable era: <code>BE</code>. If the | |
41 | * calendar is not in lenient mode (see <code>setLenient</code>), dates before | |
42 | * 1/1/1 BE are rejected as an illegal argument. | |
43 | * <p> | |
44 | * @internal | |
45 | */ | |
46 | class U_I18N_API BuddhistCalendar : public GregorianCalendar { | |
47 | public: | |
48 | ||
49 | /** | |
50 | * Useful constants for BuddhistCalendar. Only one Era. | |
51 | * @internal | |
52 | */ | |
53 | enum EEras { | |
54 | BE | |
55 | }; | |
56 | ||
57 | /** | |
58 | * Constructs a BuddhistCalendar based on the current time in the default time zone | |
59 | * with the given locale. | |
60 | * | |
61 | * @param aLocale The given locale. | |
62 | * @param success Indicates the status of BuddhistCalendar object construction. | |
63 | * Returns U_ZERO_ERROR if constructed successfully. | |
374ca955 | 64 | * @internal |
b75a7d8f A |
65 | */ |
66 | BuddhistCalendar(const Locale& aLocale, UErrorCode& success); | |
67 | ||
68 | ||
69 | /** | |
70 | * Destructor | |
71 | * @internal | |
72 | */ | |
73 | virtual ~BuddhistCalendar(); | |
74 | ||
75 | /** | |
76 | * Copy constructor | |
77 | * @param source the object to be copied. | |
78 | * @internal | |
79 | */ | |
80 | BuddhistCalendar(const BuddhistCalendar& source); | |
81 | ||
82 | /** | |
83 | * Default assignment operator | |
84 | * @param right the object to be copied. | |
85 | * @internal | |
86 | */ | |
87 | BuddhistCalendar& operator=(const BuddhistCalendar& right); | |
88 | ||
89 | /** | |
90 | * Create and return a polymorphic copy of this calendar. | |
91 | * @return return a polymorphic copy of this calendar. | |
92 | * @internal | |
93 | */ | |
94 | virtual Calendar* clone(void) const; | |
95 | ||
b75a7d8f | 96 | public: |
b75a7d8f A |
97 | /** |
98 | * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual | |
99 | * override. This method is to implement a simple version of RTTI, since not all C++ | |
100 | * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call | |
101 | * this method. | |
102 | * | |
103 | * @return The class ID for this object. All objects of a given class have the | |
104 | * same class ID. Objects of other classes have different class IDs. | |
105 | * @internal | |
106 | */ | |
107 | virtual UClassID getDynamicClassID(void) const; | |
108 | ||
109 | /** | |
110 | * Return the class ID for this class. This is useful only for comparing to a return | |
111 | * value from getDynamicClassID(). For example: | |
112 | * | |
113 | * Base* polymorphic_pointer = createPolymorphicObject(); | |
114 | * if (polymorphic_pointer->getDynamicClassID() == | |
115 | * Derived::getStaticClassID()) ... | |
116 | * | |
117 | * @return The class ID for all objects of this class. | |
118 | * @internal | |
119 | */ | |
374ca955 | 120 | static UClassID U_EXPORT2 getStaticClassID(void); |
b75a7d8f A |
121 | |
122 | /** | |
123 | * return the calendar type, "buddhist". | |
124 | * | |
125 | * @return calendar type | |
126 | * @internal | |
127 | */ | |
128 | virtual const char * getType() const; | |
129 | ||
130 | /** | |
131 | * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount | |
132 | * of time to the given time field, based on the calendar's rules. For more | |
133 | * information, see the documentation for Calendar::add(). | |
134 | * | |
135 | * @param field The time field. | |
136 | * @param amount The amount of date or time to be added to the field. | |
137 | * @param status Output param set to success/failure code on exit. If any value | |
138 | * previously set in the time field is invalid, this will be set to | |
139 | * an error status. | |
374ca955 | 140 | * @draft ICU 2.6 |
b75a7d8f A |
141 | */ |
142 | virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status); | |
143 | ||
144 | /** | |
374ca955 A |
145 | * Gets the maximum value for the given time field. e.g. for DAY_OF_MONTH, |
146 | * 31. | |
147 | * | |
148 | * @param field The given time field. | |
149 | * @return The maximum value for the given time field. | |
150 | * @draft ICU 2.6 | |
b75a7d8f A |
151 | */ |
152 | int32_t getMaximum(UCalendarDateFields field) const; | |
374ca955 A |
153 | |
154 | /** | |
155 | * Gets the lowest maximum value for the given field if varies. Otherwise same as | |
156 | * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28. | |
157 | * | |
158 | * @param field The given time field. | |
159 | * @return The lowest maximum value for the given time field. | |
160 | * @draft ICU 2.6 | |
161 | */ | |
b75a7d8f | 162 | int32_t getLeastMaximum(UCalendarDateFields field) const; |
374ca955 A |
163 | |
164 | /** | |
165 | * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields | |
166 | */ | |
b75a7d8f | 167 | inline virtual int32_t getMaximum(EDateFields field) const { return getMaximum((UCalendarDateFields)field); } |
374ca955 A |
168 | /** |
169 | * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields | |
170 | */ | |
b75a7d8f | 171 | inline virtual int32_t getLeastMaximum(EDateFields field) const { return getLeastMaximum((UCalendarDateFields)field); } |
374ca955 A |
172 | /** |
173 | * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields | |
174 | */ | |
b75a7d8f A |
175 | inline virtual void add(EDateFields field, int32_t amount, UErrorCode& status) { add((UCalendarDateFields)field, amount, status); } |
176 | ||
b75a7d8f A |
177 | private: |
178 | BuddhistCalendar(); // default constructor not implemented | |
179 | ||
b75a7d8f | 180 | protected: |
374ca955 A |
181 | /** |
182 | * Return the extended year defined by the current fields. This will | |
183 | * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such | |
184 | * as UCAL_ERA) specific to the calendar system, depending on which set of | |
185 | * fields is newer. | |
186 | * @return the extended year | |
187 | * @internal | |
188 | */ | |
189 | virtual int32_t handleGetExtendedYear(); | |
190 | /** | |
191 | * Subclasses may override this method to compute several fields | |
192 | * specific to each calendar system. | |
193 | * @internal | |
194 | */ | |
195 | virtual void handleComputeFields(int32_t julianDay, UErrorCode& status); | |
196 | /** | |
197 | * Subclass API for defining limits of different types. | |
198 | * @param field one of the field numbers | |
199 | * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>, | |
200 | * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code> | |
201 | * @internal | |
202 | */ | |
203 | virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; | |
204 | /** | |
205 | * Return the Julian day number of day before the first day of the | |
206 | * given month in the given extended year. Subclasses should override | |
207 | * this method to implement their calendar system. | |
208 | * @param eyear the extended year | |
209 | * @param month the zero-based month, or 0 if useMonth is false | |
210 | * @param useMonth if false, compute the day before the first day of | |
211 | * the given year, otherwise, compute the day before the first day of | |
212 | * the given month | |
213 | * @param return the Julian day number of the day before the first | |
214 | * day of the given month and year | |
215 | * @internal | |
216 | */ | |
217 | virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, | |
218 | UBool useMonth) const; | |
219 | ||
220 | /** | |
221 | * month length of current month | |
222 | * @internal | |
223 | */ | |
b75a7d8f | 224 | virtual int32_t monthLength(int32_t month) const; |
374ca955 A |
225 | /** |
226 | * month length of month | |
227 | * @internal | |
228 | */ | |
b75a7d8f | 229 | virtual int32_t monthLength(int32_t month, int32_t year) const; |
374ca955 A |
230 | |
231 | /** | |
232 | * month length of current month | |
233 | * @internal | |
234 | */ | |
b75a7d8f A |
235 | int32_t getGregorianYear(UErrorCode& status) const; |
236 | ||
374ca955 A |
237 | /** |
238 | * Calculate the era for internal computation | |
239 | * @internal | |
240 | */ | |
b75a7d8f | 241 | virtual int32_t internalGetEra() const; |
374ca955 A |
242 | |
243 | /** | |
244 | * Returns TRUE because the Buddhist Calendar does have a default century | |
245 | * @internal | |
246 | */ | |
b75a7d8f | 247 | virtual UBool haveDefaultCentury() const; |
374ca955 A |
248 | |
249 | /** | |
250 | * Returns the date of the start of the default century | |
251 | * @return start of century - in milliseconds since epoch, 1970 | |
252 | * @internal | |
253 | */ | |
b75a7d8f | 254 | virtual UDate defaultCenturyStart() const; |
374ca955 A |
255 | |
256 | /** | |
257 | * Returns the year in which the default century begins | |
258 | * @internal | |
259 | */ | |
b75a7d8f A |
260 | virtual int32_t defaultCenturyStartYear() const; |
261 | ||
262 | private: // default century stuff. | |
263 | /** | |
264 | * The system maintains a static default century start date. This is initialized | |
265 | * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to | |
266 | * indicate an uninitialized state. Once the system default century date and year | |
267 | * are set, they do not change. | |
268 | */ | |
269 | static UDate fgSystemDefaultCenturyStart; | |
270 | ||
271 | /** | |
272 | * See documentation for systemDefaultCenturyStart. | |
273 | */ | |
274 | static int32_t fgSystemDefaultCenturyStartYear; | |
275 | ||
276 | /** | |
277 | * Default value that indicates the defaultCenturyStartYear is unitialized | |
278 | */ | |
279 | static const int32_t fgSystemDefaultCenturyYear; | |
280 | ||
374ca955 A |
281 | /** |
282 | * start of default century, as a date | |
283 | */ | |
b75a7d8f A |
284 | static const UDate fgSystemDefaultCentury; |
285 | ||
286 | /** | |
374ca955 A |
287 | * Returns the beginning date of the 100-year window that dates |
288 | * with 2-digit years are considered to fall within. | |
b75a7d8f A |
289 | */ |
290 | UDate internalGetDefaultCenturyStart(void) const; | |
291 | ||
292 | /** | |
374ca955 A |
293 | * Returns the first year of the 100-year window that dates with |
294 | * 2-digit years are considered to fall within. | |
b75a7d8f A |
295 | */ |
296 | int32_t internalGetDefaultCenturyStartYear(void) const; | |
297 | ||
298 | /** | |
374ca955 A |
299 | * Initializes the 100-year window that dates with 2-digit years |
300 | * are considered to fall within so that its start date is 80 years | |
301 | * before the current time. | |
b75a7d8f A |
302 | */ |
303 | static void initializeSystemDefaultCentury(void); | |
304 | }; | |
305 | ||
b75a7d8f A |
306 | U_NAMESPACE_END |
307 | ||
308 | #endif /* #if !UCONFIG_NO_FORMATTING */ | |
309 | ||
310 | #endif // _GREGOCAL | |
311 | //eof | |
312 |