Home | History | Annotate | Download | only in i18n
      1 /*
      2 *******************************************************************************
      3 * Copyright (C) 2003 - 2008, International Business Machines Corporation and  *
      4 * others. All Rights Reserved.                                                *
      5 *******************************************************************************
      6 */
      7 
      8 #ifndef ETHPCCAL_H
      9 #define ETHPCCAL_H
     10 
     11 #include "unicode/utypes.h"
     12 
     13 #if !UCONFIG_NO_FORMATTING
     14 
     15 #include "unicode/calendar.h"
     16 #include "cecal.h"
     17 
     18 U_NAMESPACE_BEGIN
     19 
     20 /**
     21  * Implement the Ethiopic calendar system.
     22  * @internal
     23  */
     24 class EthiopicCalendar : public CECalendar {
     25 
     26 public:
     27     /**
     28      * Calendar type - use Amete Alem era for all the time or not
     29      * @internal
     30      */
     31     enum EEraType {
     32         AMETE_MIHRET_ERA,
     33         AMETE_ALEM_ERA
     34     };
     35 
     36     /**
     37      * Useful constants for EthiopicCalendar.
     38      * @internal
     39      */
     40     enum EMonths {
     41         /**
     42          * Constant for መስከረም, the 1st month of the Ethiopic year.
     43          */
     44         MESKEREM,
     45 
     46         /**
     47          * Constant for ጥቅምት, the 2nd month of the Ethiopic year.
     48          */
     49         TEKEMT,
     50 
     51         /**
     52          * Constant for ኅዳር, the 3rd month of the Ethiopic year.
     53          */
     54         HEDAR,
     55 
     56         /**
     57          * Constant for ታኅሣሥ, the 4th month of the Ethiopic year.
     58          */
     59         TAHSAS,
     60 
     61         /**
     62          * Constant for ጥር, the 5th month of the Ethiopic year.
     63          */
     64         TER,
     65 
     66         /**
     67          * Constant for የካቲት, the 6th month of the Ethiopic year.
     68          */
     69         YEKATIT,
     70 
     71         /**
     72          * Constant for መጋቢት, the 7th month of the Ethiopic year.
     73          */
     74         MEGABIT,
     75 
     76         /**
     77          * Constant for ሚያዝያ, the 8th month of the Ethiopic year.
     78          */
     79         MIAZIA,
     80 
     81         /**
     82          * Constant for ግንቦት, the 9th month of the Ethiopic year.
     83          */
     84         GENBOT,
     85 
     86         /**
     87          * Constant for ሰኔ, the 10th month of the Ethiopic year.
     88          */
     89         SENE,
     90 
     91         /**
     92          * Constant for ሐምሌ, the 11th month of the Ethiopic year.
     93          */
     94         HAMLE,
     95 
     96         /**
     97          * Constant for ነሐሴ, the 12th month of the Ethiopic year.
     98          */
     99         NEHASSA,
    100 
    101         /**
    102          * Constant for ጳጉሜን, the 13th month of the Ethiopic year.
    103          */
    104         PAGUMEN
    105     };
    106 
    107     enum EEras {
    108         AMETE_ALEM,     // Before the epoch
    109         AMETE_MIHRET    // After the epoch
    110     };
    111 
    112     /**
    113      * Constructs a EthiopicCalendar based on the current time in the default time zone
    114      * with the given locale.
    115      *
    116      * @param aLocale  The given locale.
    117      * @param success  Indicates the status of EthiopicCalendar object construction.
    118      *                 Returns U_ZERO_ERROR if constructed successfully.
    119      * @param type     Whether this Ethiopic calendar use Amete Mihrret (default) or
    120      *                 only use Amete Alem for all the time.
    121      * @internal
    122      */
    123     EthiopicCalendar(const Locale& aLocale, UErrorCode& success, EEraType type = AMETE_MIHRET_ERA);
    124 
    125     /**
    126      * Copy Constructor
    127      * @internal
    128      */
    129     EthiopicCalendar(const EthiopicCalendar& other);
    130 
    131     /**
    132      * Destructor.
    133      * @internal
    134      */
    135     virtual ~EthiopicCalendar();
    136 
    137     /**
    138      * Create and return a polymorphic copy of this calendar.
    139      * @return    return a polymorphic copy of this calendar.
    140      * @internal
    141      */
    142     virtual Calendar* clone() const;
    143 
    144     /**
    145      * return the calendar type, "ethiopic"
    146      * @return calendar type
    147      * @internal
    148      */
    149     virtual const char * getType() const;
    150 
    151     /**
    152      * Set Alem or Mihret era.
    153      * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
    154      * @internal
    155      */
    156     void setAmeteAlemEra (UBool onOff);
    157 
    158     /**
    159      * Return true if this calendar is set to the Amete Alem era.
    160      * @return true if set to the Amete Alem era.
    161      * @internal
    162      */
    163     UBool isAmeteAlemEra() const;
    164 
    165 protected:
    166     //-------------------------------------------------------------------------
    167     // Calendar framework
    168     //-------------------------------------------------------------------------
    169 
    170     /**
    171      * Return the extended year defined by the current fields.
    172      * @internal
    173      */
    174     virtual int32_t handleGetExtendedYear();
    175 
    176     /**
    177      * Compute fields from the JD
    178      * @internal
    179      */
    180     virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
    181 
    182     /**
    183      * Calculate the limit for a specified type of limit and field
    184      * @internal
    185      */
    186     virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
    187 
    188     /**
    189      * Returns the date of the start of the default century
    190      * @return start of century - in milliseconds since epoch, 1970
    191      * @internal
    192      */
    193     virtual UDate defaultCenturyStart() const;
    194 
    195     /**
    196      * Returns the year in which the default century begins
    197      * @internal
    198      */
    199     virtual int32_t defaultCenturyStartYear() const;
    200 
    201     /**
    202      * Return the date offset from Julian
    203      * @internal
    204      */
    205     virtual int32_t getJDEpochOffset() const;
    206 
    207 private:
    208     /**
    209      * The system maintains a static default century start date.  This is initialized
    210      * the first time it is used.  Before then, it is set to SYSTEM_DEFAULT_CENTURY to
    211      * indicate an uninitialized state.  Once the system default century date and year
    212      * are set, they do not change.
    213      */
    214     static UDate fgSystemDefaultCenturyStart;
    215 
    216     /**
    217      * See documentation for systemDefaultCenturyStart.
    218      */
    219     static int32_t fgSystemDefaultCenturyStartYear;
    220 
    221     /**
    222      * Default value that indicates the defaultCenturyStartYear is unitialized
    223      */
    224     static const int32_t fgSystemDefaultCenturyYear;
    225 
    226     /**
    227      * start of default century, as a date
    228      */
    229     static const UDate fgSystemDefaultCentury;
    230 
    231     /**
    232      * Initializes the 100-year window that dates with 2-digit years
    233      * are considered to fall within so that its start date is 80 years
    234      * before the current time.
    235      */
    236     static void initializeSystemDefaultCentury(void);
    237 
    238     /**
    239      * When eraType is AMETE_ALEM_ERA, then this calendar use only AMETE_ALEM
    240      * for the era. Otherwise (default), this calendar uses both AMETE_ALEM
    241      * and AMETE_MIHRET.
    242      *
    243      * EXTENDED_YEAR        AMETE_ALEM_ERA     AMETE_MIHRET_ERA
    244      *             0       Amete Alem 5500      Amete Alem 5500
    245      *             1        Amete Mihret 1      Amete Alem 5501
    246      */
    247     EEraType eraType;
    248 
    249 public:
    250     /**
    251      * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
    252      * override. This method is to implement a simple version of RTTI, since not all C++
    253      * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
    254      * this method.
    255      *
    256      * @return   The class ID for this object. All objects of a given class have the
    257      *           same class ID. Objects of other classes have different class IDs.
    258      * @internal
    259      */
    260     virtual UClassID getDynamicClassID(void) const;
    261 
    262     /**
    263      * Return the class ID for this class. This is useful only for comparing to a return
    264      * value from getDynamicClassID(). For example:
    265      *
    266      *      Base* polymorphic_pointer = createPolymorphicObject();
    267      *      if (polymorphic_pointer->getDynamicClassID() ==
    268      *          Derived::getStaticClassID()) ...
    269      *
    270      * @return   The class ID for all objects of this class.
    271      * @internal
    272      */
    273     U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
    274 
    275 #if 0
    276 // We do not want to introduce this API in ICU4C.
    277 // It was accidentally introduced in ICU4J as a public API.
    278 
    279 public:
    280     //-------------------------------------------------------------------------
    281     // Calendar system Conversion methods...
    282     //-------------------------------------------------------------------------
    283 
    284     /**
    285      * Convert an Ethiopic year, month, and day to a Julian day.
    286      *
    287      * @param year the extended year
    288      * @param month the month
    289      * @param day the day
    290      * @return Julian day
    291      * @internal
    292      */
    293     int32_t ethiopicToJD(int32_t year, int32_t month, int32_t day);
    294 #endif
    295 };
    296 
    297 U_NAMESPACE_END
    298 #endif /* #if !UCONFIG_NO_FORMATTING */
    299 #endif /* ETHPCCAL_H */
    300 //eof
    301