2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.util;
\r
10 import com.ibm.icu.util.TimeZone;
\r
11 import java.util.Date;
\r
12 import java.util.Locale;
\r
15 * <code>TaiwanCalendar</code> is a subclass of <code>GregorianCalendar</code>
\r
16 * that numbers years since 1912.
\r
18 * The Taiwan calendar is identical to the Gregorian calendar in all respects
\r
19 * except for the year and era. Years are numbered since 1912 AD (Gregorian).
\r
21 * The Taiwan Calendar has one era: <code>MINGUO</code>.
\r
23 * This class should not be subclassed.</p>
\r
25 * TaiwanCalendar usually should be instantiated using
\r
26 * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
\r
27 * with the tag <code>"@calendar=roc"</code>.</p>
\r
29 * @see com.ibm.icu.util.Calendar
\r
30 * @see com.ibm.icu.util.GregorianCalendar
\r
32 * @author Laura Werner
\r
34 * @author Steven R. Loomis
\r
37 public class TaiwanCalendar extends GregorianCalendar {
\r
38 // jdk1.4.2 serialver
\r
39 private static final long serialVersionUID = 2583005278132380631L;
\r
41 //-------------------------------------------------------------------------
\r
43 //-------------------------------------------------------------------------
\r
46 * Constant for the Taiwan Era for years before Minguo 1.
\r
47 * Brefore Minuo 1 is Gregorian 1911, Before Minguo 2 is Gregorian 1910
\r
50 * @see com.ibm.icu.util.Calendar#ERA
\r
53 public static final int BEFORE_MINGUO = 0;
\r
56 * Constant for the Taiwan Era for Minguo. Minguo 1 is 1912 in
\r
57 * Gregorian calendar.
\r
59 * @see com.ibm.icu.util.Calendar#ERA
\r
62 public static final int MINGUO = 1;
\r
65 * Constructs a <code>TaiwanCalendar</code> using the current time
\r
66 * in the default time zone with the default locale.
\r
69 public TaiwanCalendar() {
\r
74 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
75 * in the given time zone with the default locale.
\r
77 * @param zone the given time zone.
\r
80 public TaiwanCalendar(TimeZone zone) {
\r
85 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
86 * in the default time zone with the given locale.
\r
88 * @param aLocale the given locale.
\r
91 public TaiwanCalendar(Locale aLocale) {
\r
96 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
97 * in the default time zone with the given locale.
\r
99 * @param locale the given ulocale.
\r
102 public TaiwanCalendar(ULocale locale) {
\r
107 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
108 * in the given time zone with the given locale.
\r
110 * @param zone the given time zone.
\r
114 public TaiwanCalendar(TimeZone zone, Locale aLocale) {
\r
115 super(zone, aLocale);
\r
119 * Constructs a <code>TaiwanCalendar</code> based on the current time
\r
120 * in the given time zone with the given locale.
\r
122 * @param zone the given time zone.
\r
123 * @param locale the given ulocale.
\r
126 public TaiwanCalendar(TimeZone zone, ULocale locale) {
\r
127 super(zone, locale);
\r
131 * Constructs a <code>TaiwanCalendar</code> with the given date set
\r
132 * in the default time zone with the default locale.
\r
134 * @param date The date to which the new calendar is set.
\r
137 public TaiwanCalendar(Date date) {
\r
143 * Constructs a <code>TaiwanCalendar</code> with the given date set
\r
144 * in the default time zone with the default locale.
\r
146 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
148 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
149 * The value is 0-based. e.g., 0 for January.
\r
151 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
154 public TaiwanCalendar(int year, int month, int date) {
\r
155 super(year, month, date);
\r
159 * Constructs a TaiwanCalendar with the given date
\r
160 * and time set for the default time zone with the default locale.
\r
162 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
164 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
165 * The value is 0-based. e.g., 0 for January.
\r
166 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
167 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
\r
168 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
\r
169 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
\r
172 public TaiwanCalendar(int year, int month, int date, int hour,
\r
173 int minute, int second)
\r
175 super(year, month, date, hour, minute, second);
\r
179 //-------------------------------------------------------------------------
\r
180 // The only practical difference from a Gregorian calendar is that years
\r
181 // are numbered since 1912, inclusive. A couple of overrides will
\r
182 // take care of that....
\r
183 //-------------------------------------------------------------------------
\r
185 private static final int Taiwan_ERA_START = 1911; // 0=1911, 1=1912
\r
187 // Use 1970 as the default value of EXTENDED_YEAR
\r
188 private static final int GREGORIAN_EPOCH = 1970;
\r
195 protected int handleGetExtendedYear() {
\r
196 // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year
\r
197 // The default value of EXTENDED_YEAR is 1970 (Minguo 59)
\r
198 int year = GREGORIAN_EPOCH;
\r
199 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR
\r
200 && newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) {
\r
201 year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH);
\r
203 int era = internalGet(ERA, MINGUO);
\r
204 if (era == MINGUO) {
\r
205 year = internalGet(YEAR, 1) + Taiwan_ERA_START;
\r
207 year = 1 - internalGet(YEAR, 1) + Taiwan_ERA_START;
\r
217 protected void handleComputeFields(int julianDay) {
\r
218 super.handleComputeFields(julianDay);
\r
219 int y = internalGet(EXTENDED_YEAR) - Taiwan_ERA_START;
\r
221 internalSet(ERA, MINGUO);
\r
222 internalSet(YEAR, y);
\r
224 internalSet(ERA, BEFORE_MINGUO);
\r
225 internalSet(YEAR, 1- y);
\r
230 * Override GregorianCalendar. There is only one Taiwan ERA. We
\r
231 * should really handle YEAR, YEAR_WOY, and EXTENDED_YEAR here too to
\r
232 * implement the 1..5000000 range, but it's not critical.
\r
235 protected int handleGetLimit(int field, int limitType) {
\r
236 if (field == ERA) {
\r
237 if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) {
\r
238 return BEFORE_MINGUO;
\r
243 return super.handleGetLimit(field, limitType);
\r
250 public String getType() {
\r