japancal.h 7.5 KB

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