| 1 |
// © 2016 and later: Unicode, Inc. and others. |
| 2 |
// License & terms of use: http://www.unicode.org/copyright.html |
| 3 |
/* |
| 4 |
******************************************************************************* |
| 5 |
* Copyright (C) 2003 - 2013, International Business Machines Corporation and * |
| 6 |
* others. All Rights Reserved. * |
| 7 |
******************************************************************************* |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef ETHPCCAL_H |
| 11 |
#define ETHPCCAL_H |
| 12 |
|
| 13 |
#include "unicode/utypes.h" |
| 14 |
|
| 15 |
#if !UCONFIG_NO_FORMATTING |
| 16 |
|
| 17 |
#include "unicode/calendar.h" |
| 18 |
#include "cecal.h" |
| 19 |
|
| 20 |
U_NAMESPACE_BEGIN |
| 21 |
|
| 22 |
/** |
| 23 |
* Implement the Ethiopic calendar system. |
| 24 |
* @internal |
| 25 |
*/ |
| 26 |
class EthiopicCalendar : public CECalendar { |
| 27 |
|
| 28 |
public: |
| 29 |
/** |
| 30 |
* Useful constants for EthiopicCalendar. |
| 31 |
* @internal |
| 32 |
*/ |
| 33 |
enum EMonths { |
| 34 |
/** |
| 35 |
* Constant for መስከረም, the 1st month of the Ethiopic year. |
| 36 |
*/ |
| 37 |
MESKEREM, |
| 38 |
|
| 39 |
/** |
| 40 |
* Constant for ጥቅምት, the 2nd month of the Ethiopic year. |
| 41 |
*/ |
| 42 |
TEKEMT, |
| 43 |
|
| 44 |
/** |
| 45 |
* Constant for ኅዳር, the 3rd month of the Ethiopic year. |
| 46 |
*/ |
| 47 |
HEDAR, |
| 48 |
|
| 49 |
/** |
| 50 |
* Constant for ታኅሣሥ, the 4th month of the Ethiopic year. |
| 51 |
*/ |
| 52 |
TAHSAS, |
| 53 |
|
| 54 |
/** |
| 55 |
* Constant for ጥር, the 5th month of the Ethiopic year. |
| 56 |
*/ |
| 57 |
TER, |
| 58 |
|
| 59 |
/** |
| 60 |
* Constant for የካቲት, the 6th month of the Ethiopic year. |
| 61 |
*/ |
| 62 |
YEKATIT, |
| 63 |
|
| 64 |
/** |
| 65 |
* Constant for መጋቢት, the 7th month of the Ethiopic year. |
| 66 |
*/ |
| 67 |
MEGABIT, |
| 68 |
|
| 69 |
/** |
| 70 |
* Constant for ሚያዝያ, the 8th month of the Ethiopic year. |
| 71 |
*/ |
| 72 |
MIAZIA, |
| 73 |
|
| 74 |
/** |
| 75 |
* Constant for ግንቦት, the 9th month of the Ethiopic year. |
| 76 |
*/ |
| 77 |
GENBOT, |
| 78 |
|
| 79 |
/** |
| 80 |
* Constant for ሰኔ, the 10th month of the Ethiopic year. |
| 81 |
*/ |
| 82 |
SENE, |
| 83 |
|
| 84 |
/** |
| 85 |
* Constant for ሐምሌ, the 11th month of the Ethiopic year. |
| 86 |
*/ |
| 87 |
HAMLE, |
| 88 |
|
| 89 |
/** |
| 90 |
* Constant for ነሐሴ, the 12th month of the Ethiopic year. |
| 91 |
*/ |
| 92 |
NEHASSE, |
| 93 |
|
| 94 |
/** |
| 95 |
* Constant for ጳጉሜን, the 13th month of the Ethiopic year. |
| 96 |
*/ |
| 97 |
PAGUMEN |
| 98 |
}; |
| 99 |
|
| 100 |
enum EEras { |
| 101 |
AMETE_ALEM, // Before the epoch |
| 102 |
AMETE_MIHRET // After the epoch |
| 103 |
}; |
| 104 |
|
| 105 |
/** |
| 106 |
* Constructs a EthiopicCalendar based on the current time in the default time zone |
| 107 |
* with the given locale. |
| 108 |
* |
| 109 |
* @param aLocale The given locale. |
| 110 |
* @param success Indicates the status of EthiopicCalendar object construction. |
| 111 |
* Returns U_ZERO_ERROR if constructed successfully. |
| 112 |
* @param type Whether this Ethiopic calendar use Amete Mihrret (default) or |
| 113 |
* only use Amete Alem for all the time. |
| 114 |
* @internal |
| 115 |
*/ |
| 116 |
EthiopicCalendar(const Locale& aLocale, UErrorCode& success); |
| 117 |
|
| 118 |
/** |
| 119 |
* Copy Constructor |
| 120 |
* @internal |
| 121 |
*/ |
| 122 |
EthiopicCalendar(const EthiopicCalendar& other) = default; |
| 123 |
|
| 124 |
/** |
| 125 |
* Destructor. |
| 126 |
* @internal |
| 127 |
*/ |
| 128 |
virtual ~EthiopicCalendar(); |
| 129 |
|
| 130 |
/** |
| 131 |
* Create and return a polymorphic copy of this calendar. |
| 132 |
* @return return a polymorphic copy of this calendar. |
| 133 |
* @internal |
| 134 |
*/ |
| 135 |
virtual EthiopicCalendar* clone() const override; |
| 136 |
|
| 137 |
/** |
| 138 |
* Return the calendar type, "ethiopic" |
| 139 |
* @return calendar type |
| 140 |
* @internal |
| 141 |
*/ |
| 142 |
virtual const char * getType() const override; |
| 143 |
|
| 144 |
/** |
| 145 |
* @return The related Gregorian year; will be obtained by modifying the value |
| 146 |
* obtained by get from UCAL_EXTENDED_YEAR field |
| 147 |
* @internal |
| 148 |
*/ |
| 149 |
virtual int32_t getRelatedYear(UErrorCode &status) const override; |
| 150 |
|
| 151 |
/** |
| 152 |
* @param year The related Gregorian year to set; will be modified as necessary then |
| 153 |
* set in UCAL_EXTENDED_YEAR field |
| 154 |
* @internal |
| 155 |
*/ |
| 156 |
virtual void setRelatedYear(int32_t year) override; |
| 157 |
|
| 158 |
protected: |
| 159 |
//------------------------------------------------------------------------- |
| 160 |
// Calendar framework |
| 161 |
//------------------------------------------------------------------------- |
| 162 |
|
| 163 |
/** |
| 164 |
* Return the extended year defined by the current fields. |
| 165 |
* This calendar uses both AMETE_ALEM and AMETE_MIHRET. |
| 166 |
* |
| 167 |
* EXTENDED_YEAR ERA YEAR |
| 168 |
* 0 AMETE_ALEM 5500 |
| 169 |
* 1 AMETE_MIHRET 1 |
| 170 |
* @internal |
| 171 |
*/ |
| 172 |
virtual int32_t handleGetExtendedYear(UErrorCode& status) override; |
| 173 |
|
| 174 |
/** |
| 175 |
* Compute fields from the JD |
| 176 |
* @internal |
| 177 |
*/ |
| 178 |
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override; |
| 179 |
|
| 180 |
DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY |
| 181 |
|
| 182 |
/** |
| 183 |
* Return the date offset from Julian |
| 184 |
* @internal |
| 185 |
*/ |
| 186 |
virtual int32_t getJDEpochOffset() const override; |
| 187 |
|
| 188 |
public: |
| 189 |
/** |
| 190 |
* Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual |
| 191 |
* override. This method is to implement a simple version of RTTI, since not all C++ |
| 192 |
* compilers support genuine RTTI. Polymorphic operator==() and clone() methods call |
| 193 |
* this method. |
| 194 |
* |
| 195 |
* @return The class ID for this object. All objects of a given class have the |
| 196 |
* same class ID. Objects of other classes have different class IDs. |
| 197 |
* @internal |
| 198 |
*/ |
| 199 |
virtual UClassID getDynamicClassID() const override; |
| 200 |
|
| 201 |
/** |
| 202 |
* Return the class ID for this class. This is useful only for comparing to a return |
| 203 |
* value from getDynamicClassID(). For example: |
| 204 |
* |
| 205 |
* Base* polymorphic_pointer = createPolymorphicObject(); |
| 206 |
* if (polymorphic_pointer->getDynamicClassID() == |
| 207 |
* Derived::getStaticClassID()) ... |
| 208 |
* |
| 209 |
* @return The class ID for all objects of this class. |
| 210 |
* @internal |
| 211 |
*/ |
| 212 |
U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); |
| 213 |
|
| 214 |
#if 0 |
| 215 |
// We do not want to introduce this API in ICU4C. |
| 216 |
// It was accidentally introduced in ICU4J as a public API. |
| 217 |
|
| 218 |
public: |
| 219 |
//------------------------------------------------------------------------- |
| 220 |
// Calendar system Conversion methods... |
| 221 |
//------------------------------------------------------------------------- |
| 222 |
|
| 223 |
/** |
| 224 |
* Convert an Ethiopic year, month, and day to a Julian day. |
| 225 |
* |
| 226 |
* @param year the extended year |
| 227 |
* @param month the month |
| 228 |
* @param day the day |
| 229 |
* @return Julian day |
| 230 |
* @internal |
| 231 |
*/ |
| 232 |
int32_t ethiopicToJD(int32_t year, int32_t month, int32_t day); |
| 233 |
#endif |
| 234 |
}; |
| 235 |
|
| 236 |
/** |
| 237 |
* Implement the Ethiopic Amete Alem calendar system. |
| 238 |
* @internal |
| 239 |
*/ |
| 240 |
class EthiopicAmeteAlemCalendar : public EthiopicCalendar { |
| 241 |
|
| 242 |
public: |
| 243 |
/** |
| 244 |
* Constructs a EthiopicAmeteAlemCalendar based on the current time in the default time zone |
| 245 |
* with the given locale. |
| 246 |
* |
| 247 |
* @param aLocale The given locale. |
| 248 |
* @param success Indicates the status of EthiopicCalendar object construction. |
| 249 |
* Returns U_ZERO_ERROR if constructed successfully. |
| 250 |
* @internal |
| 251 |
*/ |
| 252 |
EthiopicAmeteAlemCalendar(const Locale& aLocale, UErrorCode& success); |
| 253 |
|
| 254 |
/** |
| 255 |
* Copy Constructor |
| 256 |
* @internal |
| 257 |
*/ |
| 258 |
EthiopicAmeteAlemCalendar(const EthiopicAmeteAlemCalendar& other) = default; |
| 259 |
|
| 260 |
/** |
| 261 |
* Destructor. |
| 262 |
* @internal |
| 263 |
*/ |
| 264 |
virtual ~EthiopicAmeteAlemCalendar(); |
| 265 |
|
| 266 |
/** |
| 267 |
* Create and return a polymorphic copy of this calendar. |
| 268 |
* @return return a polymorphic copy of this calendar. |
| 269 |
* @internal |
| 270 |
*/ |
| 271 |
virtual EthiopicAmeteAlemCalendar* clone() const override; |
| 272 |
|
| 273 |
/** |
| 274 |
* Return the calendar type, "ethiopic-amete-alem" |
| 275 |
* @return calendar type |
| 276 |
* @internal |
| 277 |
*/ |
| 278 |
virtual const char * getType() const override; |
| 279 |
|
| 280 |
/** |
| 281 |
* Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual |
| 282 |
* override. This method is to implement a simple version of RTTI, since not all C++ |
| 283 |
* compilers support genuine RTTI. Polymorphic operator==() and clone() methods call |
| 284 |
* this method. |
| 285 |
* |
| 286 |
* @return The class ID for this object. All objects of a given class have the |
| 287 |
* same class ID. Objects of other classes have different class IDs. |
| 288 |
* @internal |
| 289 |
*/ |
| 290 |
virtual UClassID getDynamicClassID() const override; |
| 291 |
|
| 292 |
/** |
| 293 |
* Return the class ID for this class. This is useful only for comparing to a return |
| 294 |
* value from getDynamicClassID(). For example: |
| 295 |
* |
| 296 |
* Base* polymorphic_pointer = createPolymorphicObject(); |
| 297 |
* if (polymorphic_pointer->getDynamicClassID() == |
| 298 |
* Derived::getStaticClassID()) ... |
| 299 |
* |
| 300 |
* @return The class ID for all objects of this class. |
| 301 |
* @internal |
| 302 |
*/ |
| 303 |
U_I18N_API static UClassID U_EXPORT2 getStaticClassID(); |
| 304 |
|
| 305 |
/** |
| 306 |
* @return The related Gregorian year; will be obtained by modifying the value |
| 307 |
* obtained by get from UCAL_EXTENDED_YEAR field |
| 308 |
* @internal |
| 309 |
*/ |
| 310 |
virtual int32_t getRelatedYear(UErrorCode &status) const override; |
| 311 |
|
| 312 |
/** |
| 313 |
* @param year The related Gregorian year to set; will be modified as necessary then |
| 314 |
* set in UCAL_EXTENDED_YEAR field |
| 315 |
* @internal |
| 316 |
*/ |
| 317 |
virtual void setRelatedYear(int32_t year) override; |
| 318 |
|
| 319 |
protected: |
| 320 |
//------------------------------------------------------------------------- |
| 321 |
// Calendar framework |
| 322 |
//------------------------------------------------------------------------- |
| 323 |
|
| 324 |
/** |
| 325 |
* Return the extended year defined by the current fields. |
| 326 |
* This calendar use only AMETE_ALEM for the era. |
| 327 |
* |
| 328 |
* EXTENDED_YEAR ERA YEAR |
| 329 |
* 0 AMETE_ALEM 5500 |
| 330 |
* 1 AMETE_ALEM 5501 |
| 331 |
* @internal |
| 332 |
*/ |
| 333 |
virtual int32_t handleGetExtendedYear(UErrorCode& status) override; |
| 334 |
|
| 335 |
/** |
| 336 |
* Compute fields from the JD |
| 337 |
* @internal |
| 338 |
*/ |
| 339 |
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override; |
| 340 |
|
| 341 |
/** |
| 342 |
* Calculate the limit for a specified type of limit and field |
| 343 |
* @internal |
| 344 |
*/ |
| 345 |
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override; |
| 346 |
/** |
| 347 |
* Returns the year in which the default century begins |
| 348 |
* @internal |
| 349 |
*/ |
| 350 |
virtual int32_t defaultCenturyStartYear() const override; |
| 351 |
}; |
| 352 |
|
| 353 |
U_NAMESPACE_END |
| 354 |
#endif /* #if !UCONFIG_NO_FORMATTING */ |
| 355 |
#endif /* ETHPCCAL_H */ |
| 356 |
//eof |