001: /*
002: *******************************************************************************
003: * Copyright (C) 2005-2006, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.util;
008:
009: import java.util.Date;
010: import java.util.Locale;
011:
012: /**
013: * Implement the Ethiopic calendar system.
014: * <p>
015: * EthiopicCalendar usually should be instantiated using
016: * {@link com.ibm.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
017: * with the tag <code>"@calendar=ethiopic"</code>.</p>
018: *
019: * @see com.ibm.icu.util.Calendar
020: * @draft ICU 3.4
021: * @provisional This API might change or be removed in a future release.
022: */
023: public final class EthiopicCalendar extends CECalendar {
024: //jdk1.4.2 serialver
025: private static final long serialVersionUID = -2438495771339315608L;
026:
027: /**
028: * Constant for \u1218\u1235\u12a8\u1228\u121d, the 1st month of the Ethiopic year.
029: * @draft ICU 3.4
030: * @provisional This API might change or be removed in a future release.
031: */
032: public static final int MESKEREM = 0;
033:
034: /**
035: * Constant for \u1325\u1245\u121d\u1275, the 2nd month of the Ethiopic year.
036: * @draft ICU 3.4
037: * @provisional This API might change or be removed in a future release.
038: */
039: public static final int TEKEMT = 1;
040:
041: /**
042: * Constant for \u1285\u12f3\u122d, the 3rd month of the Ethiopic year.
043: * @draft ICU 3.4
044: * @provisional This API might change or be removed in a future release.
045: */
046: public static final int HEDAR = 2;
047:
048: /**
049: * Constant for \u1273\u1285\u1223\u1225, the 4th month of the Ethiopic year.
050: * @draft ICU 3.4
051: * @provisional This API might change or be removed in a future release.
052: */
053: public static final int TAHSAS = 3;
054:
055: /**
056: * Constant for \u1325\u122d, the 5th month of the Ethiopic year.
057: * @draft ICU 3.4
058: * @provisional This API might change or be removed in a future release.
059: */
060: public static final int TER = 4;
061:
062: /**
063: * Constant for \u12e8\u12ab\u1272\u1275, the 6th month of the Ethiopic year.
064: * @draft ICU 3.4
065: * @provisional This API might change or be removed in a future release.
066: */
067: public static final int YEKATIT = 5;
068:
069: /**
070: * Constant for \u1218\u130b\u1262\u1275, the 7th month of the Ethiopic year.
071: * @draft ICU 3.4
072: * @provisional This API might change or be removed in a future release.
073: */
074: public static final int MEGABIT = 6;
075:
076: /**
077: * Constant for \u121a\u12eb\u12dd\u12eb, the 8th month of the Ethiopic year.
078: * @draft ICU 3.4
079: * @provisional This API might change or be removed in a future release.
080: */
081: public static final int MIAZIA = 7;
082:
083: /**
084: * Constant for \u130d\u1295\u1266\u1275, the 9th month of the Ethiopic year.
085: * @draft ICU 3.4
086: * @provisional This API might change or be removed in a future release.
087: */
088: public static final int GENBOT = 8;
089:
090: /**
091: * Constant for \u1230\u1294, the 10th month of the Ethiopic year.
092: * @draft ICU 3.4
093: * @provisional This API might change or be removed in a future release.
094: */
095: public static final int SENE = 9;
096:
097: /**
098: * Constant for \u1210\u121d\u120c, the 11th month of the Ethiopic year.
099: * @draft ICU 3.4
100: * @provisional This API might change or be removed in a future release.
101: */
102: public static final int HAMLE = 10;
103:
104: /**
105: * Constant for \u1290\u1210\u1234, the 12th month of the Ethiopic year.
106: * @draft ICU 3.4
107: * @provisional This API might change or be removed in a future release.
108: */
109: public static final int NEHASSE = 11;
110:
111: /**
112: * Constant for \u1333\u1309\u121c\u1295, the 13th month of the Ethiopic year.
113: * @draft ICU 3.4
114: * @provisional This API might change or be removed in a future release.
115: */
116: public static final int PAGUMEN = 12;
117:
118: // Up until the end of the 19th century the prevailant convention was to
119: // reference the Ethiopic Calendar from the creation of the world,
120: // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d
121: // (Amete Alem 5500 BC). As Ethiopia modernized the reference epoch from
122: // the birth of Christ (\u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275)
123: // began to displace the creation of the
124: // world reference point. However, years before the birth of Christ are
125: // still referenced in the creation of the world system.
126: // Thus -100 \u12d3/\u121d
127: // would be rendered as 5400 \u12d3/\u12d3.
128: //
129: // The creation of the world in Ethiopic cannon was
130: // Meskerem 1, -5500 \u12d3/\u121d 00:00:00
131: // applying the birth of Christ reference and Ethiopian time conventions. This is
132: // 6 hours less than the Julian epoch reference point (noon). In Gregorian
133: // the date and time was July 18th -5493 BC 06:00 AM.
134:
135: // Julian Days relative to the
136: // \u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275 epoch
137: private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
138:
139: // Julian Days relative to the
140: // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d epoch
141: private static final int JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
142:
143: // initialize base class constant, common to all constructors
144: {
145: jdEpochOffset = JD_EPOCH_OFFSET_AMETE_MIHRET;
146: }
147:
148: /**
149: * Constructs a default <code>EthiopicCalendar</code> using the current time
150: * in the default time zone with the default locale.
151: *
152: * @draft ICU 3.4
153: * @provisional This API might change or be removed in a future release.
154: */
155: public EthiopicCalendar() {
156: super ();
157: }
158:
159: /**
160: * Constructs a <code>EthiopicCalendar</code> based on the current time
161: * in the given time zone with the default locale.
162: *
163: * @param zone The time zone for the new calendar.
164: *
165: * @draft ICU 3.4
166: * @provisional This API might change or be removed in a future release.
167: */
168: public EthiopicCalendar(TimeZone zone) {
169: super (zone);
170: }
171:
172: /**
173: * Constructs a <code>EthiopicCalendar</code> based on the current time
174: * in the default time zone with the given locale.
175: *
176: * @param aLocale The locale for the new calendar.
177: * @draft ICU 3.4
178: * @provisional This API might change or be removed in a future release.
179: */
180: public EthiopicCalendar(Locale aLocale) {
181: super (aLocale);
182: }
183:
184: /**
185: * Constructs a <code>EthiopicCalendar</code> based on the current time
186: * in the default time zone with the given locale.
187: *
188: * @param locale The icu locale for the new calendar.
189: *
190: * @draft ICU 3.4
191: * @provisional This API might change or be removed in a future release.
192: */
193: public EthiopicCalendar(ULocale locale) {
194: super (locale);
195: }
196:
197: /**
198: * Constructs a <code>EthiopicCalendar</code> based on the current time
199: * in the given time zone with the given locale.
200: *
201: * @param zone The time zone for the new calendar.
202: * @param aLocale The locale for the new calendar.
203: *
204: * @draft ICU 3.4
205: * @provisional This API might change or be removed in a future release.
206: */
207: public EthiopicCalendar(TimeZone zone, Locale aLocale) {
208: super (zone, aLocale);
209: }
210:
211: /**
212: * Constructs a <code>EthiopicCalendar</code> based on the current time
213: * in the given time zone with the given locale.
214: *
215: * @param zone The time zone for the new calendar.
216: * @param locale The icu locale for the new calendar.
217: *
218: * @draft ICU 3.4
219: * @provisional This API might change or be removed in a future release.
220: */
221: public EthiopicCalendar(TimeZone zone, ULocale locale) {
222: super (zone, locale);
223: }
224:
225: /**
226: * Constructs a <code>EthiopicCalendar</code> with the given date set
227: * in the default time zone with the default locale.
228: *
229: * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
230: * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
231: * The value is 0-based. e.g., 0 for Meskerem.
232: * @param date The value used to set the calendar's {@link #DATE DATE} time field.
233: *
234: * @draft ICU 3.4
235: * @provisional This API might change or be removed in a future release.
236: */
237: public EthiopicCalendar(int year, int month, int date) {
238: super (year, month, date);
239: }
240:
241: /**
242: * Constructs a <code>EthiopicCalendar</code> with the given date set
243: * in the default time zone with the default locale.
244: *
245: * @param date The date to which the new calendar is set.
246: *
247: * @draft ICU 3.4
248: * @provisional This API might change or be removed in a future release.
249: */
250: public EthiopicCalendar(Date date) {
251: super (date);
252: }
253:
254: /**
255: * Constructs a <code>EthiopicCalendar</code> with the given date
256: * and time set for the default time zone with the default locale.
257: *
258: * @param year The value used to set the calendar's {@link #YEAR YEAR} time field.
259: * @param month The value used to set the calendar's {@link #MONTH MONTH} time field.
260: * The value is 0-based. e.g., 0 for Meskerem.
261: * @param date The value used to set the calendar's {@link #DATE DATE} time field.
262: * @param hour The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
263: * @param minute The value used to set the calendar's {@link #MINUTE MINUTE} time field.
264: * @param second The value used to set the calendar's {@link #SECOND SECOND} time field.
265: *
266: * @draft ICU 3.4
267: * @provisional This API might change or be removed in a future release.
268: */
269: public EthiopicCalendar(int year, int month, int date, int hour,
270: int minute, int second) {
271: super (year, month, date, hour, minute, second);
272: }
273:
274: /**
275: * Convert an Ethiopic year, month, and day to a Julian day.
276: *
277: * @param year the year
278: * @param month the month
279: * @param date the day
280: *
281: * @draft ICU 3.4
282: * @provisional This API might change or be removed in a future release.
283: */
284: public static int EthiopicToJD(long year, int month, int date) {
285: return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
286: }
287:
288: /**
289: * @internal ICU 3.4
290: * @deprecated This API is ICU internal only.
291: */
292: public static Integer[] getDateFromJD(int julianDay) {
293: return getDateFromJD(julianDay, JD_EPOCH_OFFSET_AMETE_MIHRET);
294: }
295:
296: /**
297: * Set Alem or Mihret era.
298: *
299: * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
300: *
301: * @draft ICU 3.4
302: * @provisional This API might change or be removed in a future release.
303: */
304: public void setAmeteAlemEra(boolean onOff) {
305: this .jdEpochOffset = onOff ? JD_EPOCH_OFFSET_AMETE_ALEM
306: : JD_EPOCH_OFFSET_AMETE_MIHRET;
307: }
308:
309: /**
310: * Return true if this calendar is set to the Amete Alem era.
311: *
312: * @return true if set to the Amete Alem era.
313: *
314: * @draft ICU 3.4
315: * @provisional This API might change or be removed in a future release.
316: */
317: public boolean isAmeteAlemEra() {
318: return this .jdEpochOffset == JD_EPOCH_OFFSET_AMETE_ALEM;
319: }
320:
321: /**
322: * Return the current Calendar type.
323: * @return type of calendar (gregorian, etc.)
324: * @internal ICU 3.4
325: * @deprecated This API is ICU internal only.
326: */
327: public String getType() {
328: return "ethiopic";
329: }
330: }
|