2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.util;
\r
10 import java.util.Date;
\r
11 import java.util.Locale;
\r
14 * <code>TaiwanCalendar</code> is a subclass of <code>GregorianCalendar</code>
\r
15 * that numbers years since 1912.
\r
17 * The Taiwan calendar is identical to the Gregorian calendar in all respects
\r
18 * except for the year and era. Years are numbered since 1912 AD (Gregorian).
\r
20 * The Taiwan Calendar has one era: <code>MINGUO</code>.
\r
22 * This class should not be subclassed.</p>
\r
24 * TaiwanCalendar usually should be instantiated using
\r
25 * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
\r
26 * with the tag <code>"@calendar=roc"</code>.</p>
\r
28 * @see com.ibm.icu.util.Calendar
\r
29 * @see com.ibm.icu.util.GregorianCalendar
\r
31 * @author Laura Werner
\r
33 * @author Steven R. Loomis
\r
36 public class TaiwanCalendar extends GregorianCalendar {
\r
37 // jdk1.4.2 serialver
\r
38 private static final long serialVersionUID = 2583005278132380631L;
\r
40 //-------------------------------------------------------------------------
\r
42 //-------------------------------------------------------------------------
\r
45 * Constant for the Taiwan Era for years before Minguo 1.
\r
46 * Brefore Minuo 1 is Gregorian 1911, Before Minguo 2 is Gregorian 1910
\r
49 * @see com.ibm.icu.util.Calendar#ERA
\r
52 public static final int BEFORE_MINGUO = 0;
\r
55 * Constant for the Taiwan Era for Minguo. Minguo 1 is 1912 in
\r
56 * Gregorian calendar.
\r
58 * @see com.ibm.icu.util.Calendar#ERA
\r
61 public static final int MINGUO = 1;
\r
64 * Constructs a <code>TaiwanCalendar</code> using the current time
\r
65 * in the default time zone with the default locale.
\r
68 public TaiwanCalendar() {
\r
73 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
74 * in the given time zone with the default locale.
\r
76 * @param zone the given time zone.
\r
79 public TaiwanCalendar(TimeZone zone) {
\r
84 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
85 * in the default time zone with the given locale.
\r
87 * @param aLocale the given locale.
\r
90 public TaiwanCalendar(Locale aLocale) {
\r
95 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
96 * in the default time zone with the given locale.
\r
98 * @param locale the given ulocale.
\r
101 public TaiwanCalendar(ULocale locale) {
\r
106 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
107 * in the given time zone with the given locale.
\r
109 * @param zone the given time zone.
\r
113 public TaiwanCalendar(TimeZone zone, Locale aLocale) {
\r
114 super(zone, aLocale);
\r
118 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
119 * in the given time zone with the given locale.
\r
121 * @param zone the given time zone.
\r
122 * @param locale the given ulocale.
\r
125 public TaiwanCalendar(TimeZone zone, ULocale locale) {
\r
126 super(zone, locale);
\r
130 * Constructs a <code>TaiwanCalendar</code> with the given date set
\r
131 * in the default time zone with the default locale.
\r
133 * @param date The date to which the new calendar is set.
\r
136 public TaiwanCalendar(Date date) {
\r
142 * Constructs a <code>TaiwanCalendar</code> with the given date set
\r
143 * in the default time zone with the default locale.
\r
145 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
147 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
148 * The value is 0-based. e.g., 0 for January.
\r
150 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
153 public TaiwanCalendar(int year, int month, int date) {
\r
154 super(year, month, date);
\r
158 * Constructs a TaiwanCalendar with the given date
\r
159 * and time set for the default time zone with the default locale.
\r
161 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
163 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
164 * The value is 0-based. e.g., 0 for January.
\r
165 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
166 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
\r
167 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
\r
168 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
\r
171 public TaiwanCalendar(int year, int month, int date, int hour,
\r
172 int minute, int second)
\r
174 super(year, month, date, hour, minute, second);
\r
178 //-------------------------------------------------------------------------
\r
179 // The only practical difference from a Gregorian calendar is that years
\r
180 // are numbered since 1912, inclusive. A couple of overrides will
\r
181 // take care of that....
\r
182 //-------------------------------------------------------------------------
\r
184 private static final int Taiwan_ERA_START = 1911; // 0=1911, 1=1912
\r
186 // Use 1970 as the default value of EXTENDED_YEAR
\r
187 private static final int GREGORIAN_EPOCH = 1970;
\r
194 protected int handleGetExtendedYear() {
\r
195 // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
\r
196 // The default value of EXTENDED_YEAR is 1970 (Minguo 59)
\r
197 int year = GREGORIAN_EPOCH;
\r
198 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR
\r
199 && newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) {
\r
200 year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);
\r
202 int era = internalGet(ERA, MINGUO);
\r
203 if (era == MINGUO) {
\r
204 year = internalGet(YEAR, 1) + Taiwan_ERA_START;
\r
206 year = 1 - internalGet(YEAR, 1) + Taiwan_ERA_START;
\r
216 protected void handleComputeFields(int julianDay) {
\r
217 super.handleComputeFields(julianDay);
\r
218 int y = internalGet(EXTENDED_YEAR) - Taiwan_ERA_START;
\r
220 internalSet(ERA, MINGUO);
\r
221 internalSet(YEAR, y);
\r
223 internalSet(ERA, BEFORE_MINGUO);
\r
224 internalSet(YEAR, 1- y);
\r
229 * Override GregorianCalendar. There is only one Taiwan ERA. We
\r
230 * should really handle YEAR, YEAR_WOY, and EXTENDED_YEAR here too to
\r
231 * implement the 1..5000000 range, but it's not critical.
\r
234 protected int handleGetLimit(int field, int limitType) {
\r
235 if (field == ERA) {
\r
236 if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {
\r
237 return BEFORE_MINGUO;
\r
242 return super.handleGetLimit(field, limitType);
\r
249 public String getType() {
\r