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