Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************** |
michael@0 | 3 | * Copyright (C) 2003-2008, International Business Machines Corporation |
michael@0 | 4 | * and others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************** |
michael@0 | 6 | * |
michael@0 | 7 | * File JAPANCAL.H |
michael@0 | 8 | * |
michael@0 | 9 | * Modification History: |
michael@0 | 10 | * |
michael@0 | 11 | * Date Name Description |
michael@0 | 12 | * 05/13/2003 srl copied from gregocal.h |
michael@0 | 13 | ******************************************************************************** |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | #ifndef JAPANCAL_H |
michael@0 | 17 | #define JAPANCAL_H |
michael@0 | 18 | |
michael@0 | 19 | #include "unicode/utypes.h" |
michael@0 | 20 | |
michael@0 | 21 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 22 | |
michael@0 | 23 | #include "unicode/calendar.h" |
michael@0 | 24 | #include "unicode/gregocal.h" |
michael@0 | 25 | |
michael@0 | 26 | U_NAMESPACE_BEGIN |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Concrete class which provides the Japanese calendar. |
michael@0 | 30 | * <P> |
michael@0 | 31 | * <code>JapaneseCalendar</code> is a subclass of <code>GregorianCalendar</code> |
michael@0 | 32 | * that numbers years and eras based on the reigns of the Japanese emperors. |
michael@0 | 33 | * The Japanese calendar is identical to the Gregorian calendar in all respects |
michael@0 | 34 | * except for the year and era. The ascension of each emperor to the throne |
michael@0 | 35 | * begins a new era, and the years of that era are numbered starting with the |
michael@0 | 36 | * year of ascension as year 1. |
michael@0 | 37 | * <p> |
michael@0 | 38 | * Note that in the year of an imperial ascension, there are two possible sets |
michael@0 | 39 | * of year and era values: that for the old era and for the new. For example, a |
michael@0 | 40 | * new era began on January 7, 1989 AD. Strictly speaking, the first six days |
michael@0 | 41 | * of that year were in the Showa era, e.g. "January 6, 64 Showa", while the rest |
michael@0 | 42 | * of the year was in the Heisei era, e.g. "January 7, 1 Heisei". This class |
michael@0 | 43 | * handles this distinction correctly when computing dates. However, in lenient |
michael@0 | 44 | * mode either form of date is acceptable as input. |
michael@0 | 45 | * <p> |
michael@0 | 46 | * In modern times, eras have started on January 8, 1868 AD, Gregorian (Meiji), |
michael@0 | 47 | * July 30, 1912 (Taisho), December 25, 1926 (Showa), and January 7, 1989 (Heisei). Constants |
michael@0 | 48 | * for these eras, suitable for use in the <code>UCAL_ERA</code> field, are provided |
michael@0 | 49 | * in this class. Note that the <em>number</em> used for each era is more or |
michael@0 | 50 | * less arbitrary. Currently, the era starting in 1053 AD is era #0; however this |
michael@0 | 51 | * may change in the future as we add more historical data. Use the predefined |
michael@0 | 52 | * constants rather than using actual, absolute numbers. |
michael@0 | 53 | * <p> |
michael@0 | 54 | * @internal |
michael@0 | 55 | */ |
michael@0 | 56 | class JapaneseCalendar : public GregorianCalendar { |
michael@0 | 57 | public: |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Useful constants for JapaneseCalendar. |
michael@0 | 61 | * @internal |
michael@0 | 62 | */ |
michael@0 | 63 | U_I18N_API static uint32_t U_EXPORT2 getCurrentEra(void); // the current era |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Constructs a JapaneseCalendar based on the current time in the default time zone |
michael@0 | 67 | * with the given locale. |
michael@0 | 68 | * |
michael@0 | 69 | * @param aLocale The given locale. |
michael@0 | 70 | * @param success Indicates the status of JapaneseCalendar object construction. |
michael@0 | 71 | * Returns U_ZERO_ERROR if constructed successfully. |
michael@0 | 72 | * @stable ICU 2.0 |
michael@0 | 73 | */ |
michael@0 | 74 | JapaneseCalendar(const Locale& aLocale, UErrorCode& success); |
michael@0 | 75 | |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Destructor |
michael@0 | 79 | * @internal |
michael@0 | 80 | */ |
michael@0 | 81 | virtual ~JapaneseCalendar(); |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Copy constructor |
michael@0 | 85 | * @param source the object to be copied. |
michael@0 | 86 | * @internal |
michael@0 | 87 | */ |
michael@0 | 88 | JapaneseCalendar(const JapaneseCalendar& source); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Default assignment operator |
michael@0 | 92 | * @param right the object to be copied. |
michael@0 | 93 | * @internal |
michael@0 | 94 | */ |
michael@0 | 95 | JapaneseCalendar& operator=(const JapaneseCalendar& right); |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Create and return a polymorphic copy of this calendar. |
michael@0 | 99 | * @return return a polymorphic copy of this calendar. |
michael@0 | 100 | * @internal |
michael@0 | 101 | */ |
michael@0 | 102 | virtual Calendar* clone(void) const; |
michael@0 | 103 | |
michael@0 | 104 | /** |
michael@0 | 105 | * Return the extended year defined by the current fields. In the |
michael@0 | 106 | * Japanese calendar case, this is equal to the equivalent extended Gregorian year. |
michael@0 | 107 | * @internal |
michael@0 | 108 | */ |
michael@0 | 109 | virtual int32_t handleGetExtendedYear(); |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * Return the maximum value that this field could have, given the current date. |
michael@0 | 113 | * @internal |
michael@0 | 114 | */ |
michael@0 | 115 | virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const; |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | public: |
michael@0 | 119 | /** |
michael@0 | 120 | * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual |
michael@0 | 121 | * override. This method is to implement a simple version of RTTI, since not all C++ |
michael@0 | 122 | * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call |
michael@0 | 123 | * this method. |
michael@0 | 124 | * |
michael@0 | 125 | * @return The class ID for this object. All objects of a given class have the |
michael@0 | 126 | * same class ID. Objects of other classes have different class IDs. |
michael@0 | 127 | * @internal |
michael@0 | 128 | */ |
michael@0 | 129 | virtual UClassID getDynamicClassID(void) const; |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Return the class ID for this class. This is useful only for comparing to a return |
michael@0 | 133 | * value from getDynamicClassID(). For example: |
michael@0 | 134 | * |
michael@0 | 135 | * Base* polymorphic_pointer = createPolymorphicObject(); |
michael@0 | 136 | * if (polymorphic_pointer->getDynamicClassID() == |
michael@0 | 137 | * Derived::getStaticClassID()) ... |
michael@0 | 138 | * |
michael@0 | 139 | * @return The class ID for all objects of this class. |
michael@0 | 140 | * @internal |
michael@0 | 141 | */ |
michael@0 | 142 | U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * return the calendar type, "japanese". |
michael@0 | 146 | * |
michael@0 | 147 | * @return calendar type |
michael@0 | 148 | * @internal |
michael@0 | 149 | */ |
michael@0 | 150 | virtual const char * getType() const; |
michael@0 | 151 | |
michael@0 | 152 | /** |
michael@0 | 153 | * @return FALSE - no default century in Japanese |
michael@0 | 154 | * @internal |
michael@0 | 155 | */ |
michael@0 | 156 | virtual UBool haveDefaultCentury() const; |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Not used - no default century. |
michael@0 | 160 | * @internal |
michael@0 | 161 | */ |
michael@0 | 162 | virtual UDate defaultCenturyStart() const; |
michael@0 | 163 | /** |
michael@0 | 164 | * Not used - no default century. |
michael@0 | 165 | * @internal |
michael@0 | 166 | */ |
michael@0 | 167 | virtual int32_t defaultCenturyStartYear() const; |
michael@0 | 168 | |
michael@0 | 169 | private: |
michael@0 | 170 | JapaneseCalendar(); // default constructor not implemented |
michael@0 | 171 | |
michael@0 | 172 | protected: |
michael@0 | 173 | /** |
michael@0 | 174 | * Calculate the era for internal computation |
michael@0 | 175 | * @internal |
michael@0 | 176 | */ |
michael@0 | 177 | virtual int32_t internalGetEra() const; |
michael@0 | 178 | |
michael@0 | 179 | /** |
michael@0 | 180 | * Compute fields from the JD |
michael@0 | 181 | * @internal |
michael@0 | 182 | */ |
michael@0 | 183 | virtual void handleComputeFields(int32_t julianDay, UErrorCode& status); |
michael@0 | 184 | |
michael@0 | 185 | /** |
michael@0 | 186 | * Calculate the limit for a specified type of limit and field |
michael@0 | 187 | * @internal |
michael@0 | 188 | */ |
michael@0 | 189 | virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; |
michael@0 | 190 | |
michael@0 | 191 | /*** |
michael@0 | 192 | * Called by computeJulianDay. Returns the default month (0-based) for the year, |
michael@0 | 193 | * taking year and era into account. Will return the first month of the given era, if |
michael@0 | 194 | * the current year is an ascension year. |
michael@0 | 195 | * @param eyear the extended year |
michael@0 | 196 | * @internal |
michael@0 | 197 | */ |
michael@0 | 198 | virtual int32_t getDefaultMonthInYear(int32_t eyear); |
michael@0 | 199 | |
michael@0 | 200 | /*** |
michael@0 | 201 | * Called by computeJulianDay. Returns the default day (1-based) for the month, |
michael@0 | 202 | * taking currently-set year and era into account. Will return the first day of the given |
michael@0 | 203 | * era, if the current month is an ascension year and month. |
michael@0 | 204 | * @param eyear the extended year |
michael@0 | 205 | * @param mon the month in the year |
michael@0 | 206 | * @internal |
michael@0 | 207 | */ |
michael@0 | 208 | virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month); |
michael@0 | 209 | }; |
michael@0 | 210 | |
michael@0 | 211 | U_NAMESPACE_END |
michael@0 | 212 | |
michael@0 | 213 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
michael@0 | 214 | |
michael@0 | 215 | #endif |
michael@0 | 216 | //eof |
michael@0 | 217 |