2 *******************************************************************************
\r
3 * Copyright (C) 2005-2008, 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 * Implement the Ethiopic calendar system.
\r
16 * EthiopicCalendar usually should be instantiated using
\r
17 * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
\r
18 * with the tag <code>"@calendar=ethiopic"</code>.</p>
\r
20 * @see com.ibm.icu.util.Calendar
\r
23 public final class EthiopicCalendar extends CECalendar
\r
25 //jdk1.4.2 serialver
\r
26 private static final long serialVersionUID = -2438495771339315608L;
\r
29 * Constant for መስከረም, the 1st month of the Ethiopic year.
\r
32 public static final int MESKEREM = 0;
\r
35 * Constant for ጥቅምት, the 2nd month of the Ethiopic year.
\r
38 public static final int TEKEMT = 1;
\r
41 * Constant for ኅዳር, the 3rd month of the Ethiopic year.
\r
44 public static final int HEDAR = 2;
\r
47 * Constant for ታኅሣሥ, the 4th month of the Ethiopic year.
\r
50 public static final int TAHSAS = 3;
\r
53 * Constant for ጥር, the 5th month of the Ethiopic year.
\r
56 public static final int TER = 4;
\r
59 * Constant for የካቲት, the 6th month of the Ethiopic year.
\r
62 public static final int YEKATIT = 5;
\r
65 * Constant for መጋቢት, the 7th month of the Ethiopic year.
\r
68 public static final int MEGABIT = 6;
\r
71 * Constant for ሚያዝያ, the 8th month of the Ethiopic year.
\r
74 public static final int MIAZIA = 7;
\r
77 * Constant for ግንቦት, the 9th month of the Ethiopic year.
\r
80 public static final int GENBOT = 8;
\r
83 * Constant for ሰኔ, the 10th month of the Ethiopic year.
\r
86 public static final int SENE = 9;
\r
89 * Constant for ሐምሌ, the 11th month of the Ethiopic year.
\r
92 public static final int HAMLE = 10;
\r
95 * Constant for ነሐሴ, the 12th month of the Ethiopic year.
\r
98 public static final int NEHASSE = 11;
\r
101 * Constant for ጳጉሜን, the 13th month of the Ethiopic year.
\r
104 public static final int PAGUMEN = 12;
\r
106 // Up until the end of the 19th century the prevailant convention was to
\r
107 // reference the Ethiopic Calendar from the creation of the world,
\r
108 // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d
\r
109 // (Amete Alem 5500 BC). As Ethiopia modernized the reference epoch from
\r
110 // the birth of Christ (\u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275)
\r
111 // began to displace the creation of the
\r
112 // world reference point. However, years before the birth of Christ are
\r
113 // still referenced in the creation of the world system.
\r
114 // Thus -100 \u12d3/\u121d
\r
115 // would be rendered as 5400 \u12d3/\u12d3.
\r
117 // The creation of the world in Ethiopic cannon was
\r
118 // Meskerem 1, -5500 \u12d3/\u121d 00:00:00
\r
119 // applying the birth of Christ reference and Ethiopian time conventions. This is
\r
120 // 6 hours less than the Julian epoch reference point (noon). In Gregorian
\r
121 // the date and time was July 18th -5493 BC 06:00 AM.
\r
123 // Julian Days relative to the
\r
124 // \u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275 epoch
\r
125 // Note: we no longer use this constant
\r
126 //private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
\r
128 // Julian Days relative to the
\r
129 // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d epoch
\r
130 private static final int JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
\r
132 // The delta between Amete Alem 1 and Amete Mihret 1
\r
134 private static final int AMETE_MIHRET_DELTA = 5500;
\r
137 private static final int AMETE_ALEM = 0;
\r
138 private static final int AMETE_MIHRET = 1;
\r
140 // Era mode. When eraType is AMETE_ALEM_ERA,
\r
141 // Amete Mihret won't be used for the ERA field.
\r
142 private static final int AMETE_MIHRET_ERA = 0;
\r
143 private static final int AMETE_ALEM_ERA = 1;
\r
145 private int eraType = AMETE_MIHRET_ERA;
\r
148 * Constructs a default <code>EthiopicCalendar</code> using the current time
\r
149 * in the default time zone with the default locale.
\r
152 public EthiopicCalendar() {
\r
157 * Constructs a <code>EthiopicCalendar</code> based on the current time
\r
158 * in the given time zone with the default locale.
\r
160 * @param zone The time zone for the new calendar.
\r
163 public EthiopicCalendar(TimeZone zone) {
\r
168 * Constructs a <code>EthiopicCalendar</code> based on the current time
\r
169 * in the default time zone with the given locale.
\r
171 * @param aLocale The locale for the new calendar.
\r
174 public EthiopicCalendar(Locale aLocale) {
\r
179 * Constructs a <code>EthiopicCalendar</code> based on the current time
\r
180 * in the default time zone with the given locale.
\r
182 * @param locale The icu locale for the new calendar.
\r
185 public EthiopicCalendar(ULocale locale) {
\r
190 * Constructs a <code>EthiopicCalendar</code> based on the current time
\r
191 * in the given time zone with the given locale.
\r
193 * @param zone The time zone for the new calendar.
\r
194 * @param aLocale The locale for the new calendar.
\r
197 public EthiopicCalendar(TimeZone zone, Locale aLocale) {
\r
198 super(zone, aLocale);
\r
202 * Constructs a <code>EthiopicCalendar</code> based on the current time
\r
203 * in the given time zone with the given locale.
\r
205 * @param zone The time zone for the new calendar.
\r
206 * @param locale The icu locale for the new calendar.
\r
209 public EthiopicCalendar(TimeZone zone, ULocale locale) {
\r
210 super(zone, locale);
\r
214 * Constructs a <code>EthiopicCalendar</code> with the given date set
\r
215 * in the default time zone with the default locale.
\r
217 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
218 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
219 * The value is 0-based. e.g., 0 for Meskerem.
\r
220 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
223 public EthiopicCalendar(int year, int month, int date) {
\r
224 super(year, month, date);
\r
228 * Constructs a <code>EthiopicCalendar</code> with the given date set
\r
229 * in the default time zone with the default locale.
\r
231 * @param date The date to which the new calendar is set.
\r
234 public EthiopicCalendar(Date date) {
\r
239 * Constructs a <code>EthiopicCalendar</code> with the given date
\r
240 * and time set for the default time zone with the default locale.
\r
242 * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
\r
243 * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
\r
244 * The value is 0-based. e.g., 0 for Meskerem.
\r
245 * @param date The value used to set the calendar's {@link #DATE DATE} time field.
\r
246 * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
\r
247 * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
\r
248 * @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
\r
251 public EthiopicCalendar(int year, int month, int date, int hour,
\r
252 int minute, int second)
\r
254 super(year, month, date, hour, minute, second);
\r
259 * @return type of calendar
\r
262 public String getType() {
\r
263 if (isAmeteAlemEra()) {
\r
264 return "ethiopic-amete-alem";
\r
270 * Set Alem or Mihret era.
\r
272 * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
\r
275 public void setAmeteAlemEra(boolean onOff) {
\r
276 eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
\r
280 * Return true if this calendar is set to the Amete Alem era.
\r
282 * @return true if set to the Amete Alem era.
\r
285 public boolean isAmeteAlemEra() {
\r
286 return (eraType == AMETE_ALEM_ERA);
\r
292 * @deprecated This API is ICU internal only.
\r
294 protected int handleGetExtendedYear() {
\r
295 // Ethiopic calendar uses EXTENDED_YEAR aligned to
\r
296 // Amelete Mihret year always.
\r
298 if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
\r
299 eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1
\r
300 } else if (isAmeteAlemEra()){
\r
301 eyear = internalGet(YEAR, 1 + AMETE_MIHRET_DELTA)
\r
302 - AMETE_MIHRET_DELTA; // Default to year 1 of Amelete Mihret
\r
304 // The year defaults to the epoch start, the era to AMETE_MIHRET
\r
305 int era = internalGet(ERA, AMETE_MIHRET);
\r
306 if (era == AMETE_MIHRET) {
\r
307 eyear = internalGet(YEAR, 1); // Default to year 1
\r
309 eyear = internalGet(YEAR, 1) - AMETE_MIHRET_DELTA;
\r
318 * @deprecated This API is ICU internal only.
\r
320 protected void handleComputeFields(int julianDay) {
\r
322 int[] fields = new int[3];
\r
323 jdToCE(julianDay, getJDEpochOffset(), fields);
\r
329 if (isAmeteAlemEra()) {
\r
331 year = fields[0] + AMETE_MIHRET_DELTA;
\r
333 if (fields[0] > 0) {
\r
334 era = AMETE_MIHRET;
\r
338 year = fields[0] + AMETE_MIHRET_DELTA;
\r
342 internalSet(EXTENDED_YEAR, fields[0]);
\r
343 internalSet(ERA, era);
\r
344 internalSet(YEAR, year);
\r
345 internalSet(MONTH, fields[1]);
\r
346 internalSet(DAY_OF_MONTH, fields[2]);
\r
347 internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);
\r
353 * @deprecated This API is ICU internal only.
\r
355 protected int handleGetLimit(int field, int limitType) {
\r
356 if (isAmeteAlemEra() && field == ERA) {
\r
357 return 0; // Only one era in this mode, era is always 0
\r
359 return super.handleGetLimit(field, limitType);
\r
365 * @deprecated This API is ICU internal only.
\r
367 protected int getJDEpochOffset() {
\r
368 return JD_EPOCH_OFFSET_AMETE_MIHRET;
\r
372 * Convert an Ethiopic year, month, and day to a Julian day.
\r
374 * @param year the year
\r
375 * @param month the month
\r
376 * @param date the day
\r
378 * @draft ICU 3.4 (retain)
\r
379 * @provisional This API might change or be removed in a future release.
\r
381 // The equivalent operation can be done by public Calendar API.
\r
382 // This API was accidentally marked as @draft, but we have no good
\r
383 // reason to keep this. For now, we leave it as is, but may be
\r
384 // removed in future. 2008-03-21 yoshito
\r
385 public static int EthiopicToJD(long year, int month, int date) {
\r
386 return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
\r