1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 1996-2010, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 11package android.icu.util; 12 13import java.util.Date; 14import java.util.Locale; 15 16/** 17 * <code>TaiwanCalendar</code> is a subclass of <code>GregorianCalendar</code> 18 * that numbers years since 1912. 19 * <p> 20 * The Taiwan calendar is identical to the Gregorian calendar in all respects 21 * except for the year and era. Years are numbered since 1912 AD (Gregorian). 22 * <p> 23 * The Taiwan Calendar has one era: <code>MINGUO</code>. 24 * <p> 25 * This class should not be subclassed.</p> 26 * <p> 27 * TaiwanCalendar usually should be instantiated using 28 * {@link android.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code> 29 * with the tag <code>"@calendar=roc"</code>.</p> 30 * 31 * @see android.icu.util.Calendar 32 * @see android.icu.util.GregorianCalendar 33 * 34 * @author Laura Werner 35 * @author Alan Liu 36 * @author Steven R. Loomis 37 */ 38public class TaiwanCalendar extends GregorianCalendar { 39 // jdk1.4.2 serialver 40 private static final long serialVersionUID = 2583005278132380631L; 41 42 //------------------------------------------------------------------------- 43 // Constructors... 44 //------------------------------------------------------------------------- 45 46 /** 47 * Constant for the Taiwan Era for years before Minguo 1. 48 * Brefore Minuo 1 is Gregorian 1911, Before Minguo 2 is Gregorian 1910 49 * and so on. 50 * 51 * @see android.icu.util.Calendar#ERA 52 */ 53 public static final int BEFORE_MINGUO = 0; 54 55 /** 56 * Constant for the Taiwan Era for Minguo. Minguo 1 is 1912 in 57 * Gregorian calendar. 58 * 59 * @see android.icu.util.Calendar#ERA 60 */ 61 public static final int MINGUO = 1; 62 63 /** 64 * Constructs a <code>TaiwanCalendar</code> using the current time 65 * in the default time zone with the default locale. 66 */ 67 public TaiwanCalendar() { 68 super(); 69 } 70 71 /** 72 * Constructs a <code>TaiwanCalendar</code> based on the current time 73 * in the given time zone with the default locale. 74 * 75 * @param zone the given time zone. 76 */ 77 public TaiwanCalendar(TimeZone zone) { 78 super(zone); 79 } 80 81 /** 82 * Constructs a <code>TaiwanCalendar</code> based on the current time 83 * in the default time zone with the given locale. 84 * 85 * @param aLocale the given locale. 86 */ 87 public TaiwanCalendar(Locale aLocale) { 88 super(aLocale); 89 } 90 91 /** 92 * Constructs a <code>TaiwanCalendar</code> based on the current time 93 * in the default time zone with the given locale. 94 * 95 * @param locale the given ulocale. 96 */ 97 public TaiwanCalendar(ULocale locale) { 98 super(locale); 99 } 100 101 /** 102 * Constructs a <code>TaiwanCalendar</code> based on the current time 103 * in the given time zone with the given locale. 104 * 105 * @param zone the given time zone. 106 */ 107 public TaiwanCalendar(TimeZone zone, Locale aLocale) { 108 super(zone, aLocale); 109 } 110 111 /** 112 * Constructs a <code>TaiwanCalendar</code> based on the current time 113 * in the given time zone with the given locale. 114 * 115 * @param zone the given time zone. 116 * @param locale the given ulocale. 117 */ 118 public TaiwanCalendar(TimeZone zone, ULocale locale) { 119 super(zone, locale); 120 } 121 122 /** 123 * Constructs a <code>TaiwanCalendar</code> with the given date set 124 * in the default time zone with the default locale. 125 * 126 * @param date The date to which the new calendar is set. 127 */ 128 public TaiwanCalendar(Date date) { 129 this(); 130 setTime(date); 131 } 132 133 /** 134 * Constructs a <code>TaiwanCalendar</code> with the given date set 135 * in the default time zone with the default locale. 136 * 137 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. 138 * 139 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. 140 * The value is 0-based. e.g., 0 for January. 141 * 142 * @param date The value used to set the calendar's {@link #DATE DATE} time field. 143 */ 144 public TaiwanCalendar(int year, int month, int date) { 145 super(year, month, date); 146 } 147 148 /** 149 * Constructs a TaiwanCalendar with the given date 150 * and time set for the default time zone with the default locale. 151 * 152 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. 153 * 154 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. 155 * The value is 0-based. e.g., 0 for January. 156 * @param date The value used to set the calendar's {@link #DATE DATE} time field. 157 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field. 158 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field. 159 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field. 160 */ 161 public TaiwanCalendar(int year, int month, int date, int hour, 162 int minute, int second) 163 { 164 super(year, month, date, hour, minute, second); 165 } 166 167 168 //------------------------------------------------------------------------- 169 // The only practical difference from a Gregorian calendar is that years 170 // are numbered since 1912, inclusive. A couple of overrides will 171 // take care of that.... 172 //------------------------------------------------------------------------- 173 174 private static final int Taiwan_ERA_START = 1911; // 0=1911, 1=1912 175 176 // Use 1970 as the default value of EXTENDED_YEAR 177 private static final int GREGORIAN_EPOCH = 1970; 178 179 180 /** 181 * {@inheritDoc} 182 */ 183 protected int handleGetExtendedYear() { 184 // EXTENDED_YEAR in TaiwanCalendar is a Gregorian year 185 // The default value of EXTENDED_YEAR is 1970 (Minguo 59) 186 int year = GREGORIAN_EPOCH; 187 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR 188 && newerField(EXTENDED_YEAR, ERA) == EXTENDED_YEAR) { 189 year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH); 190 } else { 191 int era = internalGet(ERA, MINGUO); 192 if (era == MINGUO) { 193 year = internalGet(YEAR, 1) + Taiwan_ERA_START; 194 } else { 195 year = 1 - internalGet(YEAR, 1) + Taiwan_ERA_START; 196 } 197 } 198 return year; 199 } 200 201 /** 202 * {@inheritDoc} 203 */ 204 protected void handleComputeFields(int julianDay) { 205 super.handleComputeFields(julianDay); 206 int y = internalGet(EXTENDED_YEAR) - Taiwan_ERA_START; 207 if (y > 0) { 208 internalSet(ERA, MINGUO); 209 internalSet(YEAR, y); 210 } else { 211 internalSet(ERA, BEFORE_MINGUO); 212 internalSet(YEAR, 1- y); 213 } 214 } 215 216 /** 217 * Override GregorianCalendar. There is only one Taiwan ERA. We 218 * should really handle YEAR, YEAR_WOY, and EXTENDED_YEAR here too to 219 * implement the 1..5000000 range, but it's not critical. 220 */ 221 protected int handleGetLimit(int field, int limitType) { 222 if (field == ERA) { 223 if (limitType == MINIMUM || limitType == GREATEST_MINIMUM) { 224 return BEFORE_MINGUO; 225 } else { 226 return MINGUO; 227 } 228 } 229 return super.handleGetLimit(field, limitType); 230 } 231 232 /** 233 * {@inheritDoc} 234 */ 235 public String getType() { 236 return "roc"; 237 } 238} 239