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