2 * Copyright (C) 2003-2004, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 ********************************************************************************
8 * Modification History:
10 * Date Name Description
11 * 05/13/2003 srl copied from gregocal.h
12 ********************************************************************************
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
22 #include "unicode/calendar.h"
23 #include "unicode/gregocal.h"
28 * Concrete class which provides the Buddhist calendar.
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.
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.
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.
46 class U_I18N_API BuddhistCalendar
: public GregorianCalendar
{
50 * Useful constants for BuddhistCalendar. Only one Era.
58 * Constructs a BuddhistCalendar based on the current time in the default time zone
59 * with the given locale.
61 * @param aLocale The given locale.
62 * @param success Indicates the status of BuddhistCalendar object construction.
63 * Returns U_ZERO_ERROR if constructed successfully.
66 BuddhistCalendar(const Locale
& aLocale
, UErrorCode
& success
);
73 virtual ~BuddhistCalendar();
77 * @param source the object to be copied.
80 BuddhistCalendar(const BuddhistCalendar
& source
);
83 * Default assignment operator
84 * @param right the object to be copied.
87 BuddhistCalendar
& operator=(const BuddhistCalendar
& right
);
90 * Create and return a polymorphic copy of this calendar.
91 * @return return a polymorphic copy of this calendar.
94 virtual Calendar
* clone(void) const;
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
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.
107 virtual UClassID
getDynamicClassID(void) const;
110 * Return the class ID for this class. This is useful only for comparing to a return
111 * value from getDynamicClassID(). For example:
113 * Base* polymorphic_pointer = createPolymorphicObject();
114 * if (polymorphic_pointer->getDynamicClassID() ==
115 * Derived::getStaticClassID()) ...
117 * @return The class ID for all objects of this class.
120 static UClassID U_EXPORT2
getStaticClassID(void);
123 * return the calendar type, "buddhist".
125 * @return calendar type
128 virtual const char * getType() const;
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().
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
142 virtual void add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
145 * Gets the maximum value for the given time field. e.g. for DAY_OF_MONTH,
148 * @param field The given time field.
149 * @return The maximum value for the given time field.
152 int32_t getMaximum(UCalendarDateFields field
) const;
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.
158 * @param field The given time field.
159 * @return The lowest maximum value for the given time field.
162 int32_t getLeastMaximum(UCalendarDateFields field
) const;
165 * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
167 inline virtual int32_t getMaximum(EDateFields field
) const { return getMaximum((UCalendarDateFields
)field
); }
169 * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
171 inline virtual int32_t getLeastMaximum(EDateFields field
) const { return getLeastMaximum((UCalendarDateFields
)field
); }
173 * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
175 inline virtual void add(EDateFields field
, int32_t amount
, UErrorCode
& status
) { add((UCalendarDateFields
)field
, amount
, status
); }
178 BuddhistCalendar(); // default constructor not implemented
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
186 * @return the extended year
189 virtual int32_t handleGetExtendedYear();
191 * Subclasses may override this method to compute several fields
192 * specific to each calendar system.
195 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
& status
);
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>
203 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
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
213 * @param return the Julian day number of the day before the first
214 * day of the given month and year
217 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
,
218 UBool useMonth
) const;
221 * month length of current month
224 virtual int32_t monthLength(int32_t month
) const;
226 * month length of month
229 virtual int32_t monthLength(int32_t month
, int32_t year
) const;
232 * month length of current month
235 int32_t getGregorianYear(UErrorCode
& status
) const;
238 * Calculate the era for internal computation
241 virtual int32_t internalGetEra() const;
244 * Returns TRUE because the Buddhist Calendar does have a default century
247 virtual UBool
haveDefaultCentury() const;
250 * Returns the date of the start of the default century
251 * @return start of century - in milliseconds since epoch, 1970
254 virtual UDate
defaultCenturyStart() const;
257 * Returns the year in which the default century begins
260 virtual int32_t defaultCenturyStartYear() const;
262 private: // default century stuff.
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.
269 static UDate fgSystemDefaultCenturyStart
;
272 * See documentation for systemDefaultCenturyStart.
274 static int32_t fgSystemDefaultCenturyStartYear
;
277 * Default value that indicates the defaultCenturyStartYear is unitialized
279 static const int32_t fgSystemDefaultCenturyYear
;
282 * start of default century, as a date
284 static const UDate fgSystemDefaultCentury
;
287 * Returns the beginning date of the 100-year window that dates
288 * with 2-digit years are considered to fall within.
290 UDate
internalGetDefaultCenturyStart(void) const;
293 * Returns the first year of the 100-year window that dates with
294 * 2-digit years are considered to fall within.
296 int32_t internalGetDefaultCenturyStartYear(void) const;
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.
303 static void initializeSystemDefaultCentury(void);
308 #endif /* #if !UCONFIG_NO_FORMATTING */