1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 2003-2008, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ********************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 05/13/2003 srl copied from gregocal.h
15 ********************************************************************************
21 #include "unicode/utypes.h"
23 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/calendar.h"
26 #include "unicode/gregocal.h"
31 * Concrete class which provides the Japanese calendar.
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.
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.
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 1053 AD is era #0; however this
53 * may change in the future as we add more historical data. Use the predefined
54 * constants rather than using actual, absolute numbers.
58 class JapaneseCalendar
: public GregorianCalendar
{
62 * Useful constants for JapaneseCalendar.
65 U_I18N_API
static uint32_t U_EXPORT2
getCurrentEra(void); // the current era
68 * Constructs a JapaneseCalendar based on the current time in the default time zone
69 * with the given locale.
71 * @param aLocale The given locale.
72 * @param success Indicates the status of JapaneseCalendar object construction.
73 * Returns U_ZERO_ERROR if constructed successfully.
76 JapaneseCalendar(const Locale
& aLocale
, UErrorCode
& success
);
83 virtual ~JapaneseCalendar();
87 * @param source the object to be copied.
90 JapaneseCalendar(const JapaneseCalendar
& source
);
93 * Default assignment operator
94 * @param right the object to be copied.
97 JapaneseCalendar
& operator=(const JapaneseCalendar
& right
);
100 * Create and return a polymorphic copy of this calendar.
101 * @return return a polymorphic copy of this calendar.
104 virtual Calendar
* clone(void) const;
107 * Return the extended year defined by the current fields. In the
108 * Japanese calendar case, this is equal to the equivalent extended Gregorian year.
111 virtual int32_t handleGetExtendedYear();
114 * Return the maximum value that this field could have, given the current date.
117 virtual int32_t getActualMaximum(UCalendarDateFields field
, UErrorCode
& status
) const;
122 * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
123 * override. This method is to implement a simple version of RTTI, since not all C++
124 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
127 * @return The class ID for this object. All objects of a given class have the
128 * same class ID. Objects of other classes have different class IDs.
131 virtual UClassID
getDynamicClassID(void) const;
134 * Return the class ID for this class. This is useful only for comparing to a return
135 * value from getDynamicClassID(). For example:
137 * Base* polymorphic_pointer = createPolymorphicObject();
138 * if (polymorphic_pointer->getDynamicClassID() ==
139 * Derived::getStaticClassID()) ...
141 * @return The class ID for all objects of this class.
144 U_I18N_API
static UClassID U_EXPORT2
getStaticClassID(void);
147 * return the calendar type, "japanese".
149 * @return calendar type
152 virtual const char * getType() const;
155 * @return FALSE - no default century in Japanese
158 virtual UBool
haveDefaultCentury() const;
161 * Not used - no default century.
164 virtual UDate
defaultCenturyStart() const;
166 * Not used - no default century.
169 virtual int32_t defaultCenturyStartYear() const;
172 JapaneseCalendar(); // default constructor not implemented
176 * Calculate the era for internal computation
179 virtual int32_t internalGetEra() const;
182 * Compute fields from the JD
185 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
& status
);
188 * Calculate the limit for a specified type of limit and field
191 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
194 * Called by computeJulianDay. Returns the default month (0-based) for the year,
195 * taking year and era into account. Will return the first month of the given era, if
196 * the current year is an ascension year.
197 * @param eyear the extended year
200 virtual int32_t getDefaultMonthInYear(int32_t eyear
);
203 * Called by computeJulianDay. Returns the default day (1-based) for the month,
204 * taking currently-set year and era into account. Will return the first day of the given
205 * era, if the current month is an ascension year and month.
206 * @param eyear the extended year
207 * @param mon the month in the year
210 virtual int32_t getDefaultDayInMonth(int32_t eyear
, int32_t month
);
215 #endif /* #if !UCONFIG_NO_FORMATTING */