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