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