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-2012, 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>BuddhistCalendar</code> is a subclass of <code>GregorianCalendar</code> 18 * that numbers years since the birth of the Buddha. This is the civil calendar 19 * in some predominantly Buddhist countries such as Thailand, and it is used for 20 * religious purposes elsewhere. 21 * <p> 22 * The Buddhist calendar is identical to the Gregorian calendar in all respects 23 * except for the year and era. Years are numbered since the birth of the 24 * Buddha in 543 BC (Gregorian), so that 1 AD (Gregorian) is equivalent to 544 25 * BE (Buddhist Era) and 1998 AD is 2541 BE. 26 * <p> 27 * The Buddhist Calendar has only one allowable era: <code>BE</code>. If the 28 * calendar is not in lenient mode (see <code>setLenient</code>), dates before 29 * 1/1/1 BE are rejected with an <code>IllegalArgumentException</code>. 30 * <p> 31 * This class should not be subclassed.</p> 32 * <p> 33 * BuddhistCalendar usually should be instantiated using 34 * {@link android.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code> 35 * with the tag <code>"@calendar=buddhist"</code>.</p> 36 * 37 * @see android.icu.util.Calendar 38 * @see android.icu.util.GregorianCalendar 39 * 40 * @author Laura Werner 41 * @author Alan Liu 42 */ 43public class BuddhistCalendar extends GregorianCalendar { 44 // jdk1.4.2 serialver 45 private static final long serialVersionUID = 2583005278132380631L; 46 47 //------------------------------------------------------------------------- 48 // Constructors... 49 //------------------------------------------------------------------------- 50 51 /** 52 * Constant for the Buddhist Era. This is the only allowable <code>ERA</code> 53 * value for the Buddhist calendar. 54 * 55 * @see android.icu.util.Calendar#ERA 56 */ 57 public static final int BE = 0; 58 59 /** 60 * Constructs a <code>BuddhistCalendar</code> using the current time 61 * in the default time zone with the default locale. 62 */ 63 public BuddhistCalendar() { 64 super(); 65 } 66 67 /** 68 * Constructs a <code>BuddhistCalendar</code> based on the current time 69 * in the given time zone with the default locale. 70 * 71 * @param zone the given time zone. 72 */ 73 public BuddhistCalendar(TimeZone zone) { 74 super(zone); 75 } 76 77 /** 78 * Constructs a <code>BuddhistCalendar</code> based on the current time 79 * in the default time zone with the given locale. 80 * 81 * @param aLocale the given locale. 82 */ 83 public BuddhistCalendar(Locale aLocale) { 84 super(aLocale); 85 } 86 87 /** 88 * Constructs a <code>BuddhistCalendar</code> based on the current time 89 * in the default time zone with the given locale. 90 * 91 * @param locale the given ulocale. 92 */ 93 public BuddhistCalendar(ULocale locale) { 94 super(locale); 95 } 96 97 /** 98 * Constructs a <code>BuddhistCalendar</code> based on the current time 99 * in the given time zone with the given locale. 100 * 101 * @param zone the given time zone. 102 * 103 * @param aLocale the given locale. 104 */ 105 public BuddhistCalendar(TimeZone zone, Locale aLocale) { 106 super(zone, aLocale); 107 } 108 109 /** 110 * Constructs a <code>BuddhistCalendar</code> based on the current time 111 * in the given time zone with the given locale. 112 * 113 * @param zone the given time zone. 114 * 115 * @param locale the given ulocale. 116 */ 117 public BuddhistCalendar(TimeZone zone, ULocale locale) { 118 super(zone, locale); 119 } 120 121 /** 122 * Constructs a <code>BuddhistCalendar</code> with the given date set 123 * in the default time zone with the default locale. 124 * 125 * @param date The date to which the new calendar is set. 126 */ 127 public BuddhistCalendar(Date date) { 128 this(); 129 setTime(date); 130 } 131 132 /** 133 * Constructs a <code>BuddhistCalendar</code> with the given date set 134 * in the default time zone with the default locale. 135 * 136 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. 137 * 138 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. 139 * The value is 0-based. e.g., 0 for January. 140 * 141 * @param date The value used to set the calendar's {@link #DATE DATE} time field. 142 */ 143 public BuddhistCalendar(int year, int month, int date) { 144 super(year, month, date); 145 } 146 147 /** 148 * Constructs a BuddhistCalendar with the given date 149 * and time set for the default time zone with the default locale. 150 * 151 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field. 152 * 153 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field. 154 * The value is 0-based. e.g., 0 for January. 155 * 156 * @param date The value used to set the calendar's {@link #DATE DATE} time field. 157 * 158 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field. 159 * 160 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field. 161 * 162 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field. 163 */ 164 public BuddhistCalendar(int year, int month, int date, int hour, 165 int minute, int second) 166 { 167 super(year, month, date, hour, minute, second); 168 } 169 170 171 //------------------------------------------------------------------------- 172 // The only practical difference from a Gregorian calendar is that years 173 // are numbered since the birth of the Buddha. A couple of overrides will 174 // take care of that.... 175 //------------------------------------------------------------------------- 176 177 // Starts in -543 AD, ie 544 BC 178 private static final int BUDDHIST_ERA_START = -543; 179 180 // Use 1970 as the default value of EXTENDED_YEAR 181 private static final int GREGORIAN_EPOCH = 1970; 182 183 /** 184 */ 185 protected int handleGetExtendedYear() { 186 // EXTENDED_YEAR in BuddhistCalendar is a Gregorian year 187 // The default value of EXTENDED_YEAR is 1970 (Buddhist 2513) 188 int year; 189 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) { 190 year = internalGet(EXTENDED_YEAR, GREGORIAN_EPOCH); 191 } else { 192 year = internalGet(YEAR, GREGORIAN_EPOCH - BUDDHIST_ERA_START) 193 + BUDDHIST_ERA_START; 194 } 195 return year; 196 } 197 198 // Return JD of start of given month/year 199 /** 200 */ 201 protected int handleComputeMonthStart(int eyear, int month, boolean useMonth) { 202 return super.handleComputeMonthStart(eyear, month, useMonth); 203 } 204 205 /** 206 */ 207 protected void handleComputeFields(int julianDay) { 208 super.handleComputeFields(julianDay); 209 int y = internalGet(EXTENDED_YEAR) - BUDDHIST_ERA_START; 210 internalSet(ERA, 0); 211 internalSet(YEAR, y); 212 } 213 214 /** 215 * Override GregorianCalendar. There is only one Buddhist ERA. We 216 * should really handle YEAR, YEAR_WOY, and EXTENDED_YEAR here too to 217 * implement the 1..5000000 range, but it's not critical. 218 */ 219 protected int handleGetLimit(int field, int limitType) { 220 if (field == ERA) { 221 return BE; 222 } 223 return super.handleGetLimit(field, limitType); 224 } 225 226 /** 227 * {@inheritDoc} 228 */ 229 public String getType() { 230 return "buddhist"; 231 } 232} 233