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