]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/EthiopicCalendar.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / util / EthiopicCalendar.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2005-2012, International Business Machines Corporation and
4  * others. All Rights Reserved.
5  *******************************************************************************
6  */
7
8 package com.ibm.icu.util;
9
10 import java.util.Date;
11 import java.util.Locale;
12
13 /**
14  * Implement the Ethiopic calendar system.
15  * <p>
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>
19  *
20  * @see com.ibm.icu.util.Calendar
21  * @stable ICU 3.4
22  */
23 public final class EthiopicCalendar extends CECalendar 
24 {
25     //jdk1.4.2 serialver
26     private static final long serialVersionUID = -2438495771339315608L;
27
28     /** 
29      * Constant for &#x1218;&#x1235;&#x12a8;&#x1228;&#x121d;, the 1st month of the Ethiopic year.
30      * @stable ICU 3.4
31      */
32     public static final int MESKEREM = 0;
33
34     /** 
35      * Constant for &#x1325;&#x1245;&#x121d;&#x1275;, the 2nd month of the Ethiopic year. 
36      * @stable ICU 3.4
37      */
38     public static final int TEKEMT = 1;
39
40     /** 
41      * Constant for &#x1285;&#x12f3;&#x122d;, the 3rd month of the Ethiopic year. 
42      * @stable ICU 3.4
43      */
44     public static final int HEDAR = 2;
45
46     /** 
47      * Constant for &#x1273;&#x1285;&#x1223;&#x1225;, the 4th month of the Ethiopic year. 
48      * @stable ICU 3.4
49      */
50     public static final int TAHSAS = 3;
51
52     /** 
53      * Constant for &#x1325;&#x122d;, the 5th month of the Ethiopic year. 
54      * @stable ICU 3.4
55      */
56     public static final int TER = 4;
57
58     /** 
59      * Constant for &#x12e8;&#x12ab;&#x1272;&#x1275;, the 6th month of the Ethiopic year. 
60      * @stable ICU 3.4
61      */
62     public static final int YEKATIT = 5;
63
64     /** 
65      * Constant for &#x1218;&#x130b;&#x1262;&#x1275;, the 7th month of the Ethiopic year. 
66      * @stable ICU 3.4
67      */
68     public static final int MEGABIT = 6;
69
70     /** 
71      * Constant for &#x121a;&#x12eb;&#x12dd;&#x12eb;, the 8th month of the Ethiopic year. 
72      * @stable ICU 3.4
73      */
74     public static final int MIAZIA = 7;
75
76     /** 
77      * Constant for &#x130d;&#x1295;&#x1266;&#x1275;, the 9th month of the Ethiopic year. 
78      * @stable ICU 3.4
79      */
80     public static final int GENBOT = 8;
81
82     /** 
83      * Constant for &#x1230;&#x1294;, the 10th month of the Ethiopic year. 
84      * @stable ICU 3.4
85      */
86     public static final int SENE = 9;
87
88     /** 
89      * Constant for &#x1210;&#x121d;&#x120c;, the 11th month of the Ethiopic year. 
90      * @stable ICU 3.4
91      */
92     public static final int HAMLE = 10;
93
94     /** 
95      * Constant for &#x1290;&#x1210;&#x1234;, the 12th month of the Ethiopic year. 
96      * @stable ICU 3.4
97      */
98     public static final int NEHASSE = 11;
99
100     /** 
101      * Constant for &#x1333;&#x1309;&#x121c;&#x1295;, the 13th month of the Ethiopic year. 
102      * @stable ICU 3.4
103      */
104     public static final int PAGUMEN = 12;
105  
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.
116     //
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.
122
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;
127
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;
131
132     // The delta between Amete Alem 1 and Amete Mihret 1
133     // AA 5501 = AM 1
134     private static final int AMETE_MIHRET_DELTA = 5500;
135
136     // Eras
137     private static final int AMETE_ALEM = 0;
138     private static final int AMETE_MIHRET = 1;
139
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;
144
145     private int eraType = AMETE_MIHRET_ERA;
146
147     /**
148      * Constructs a default <code>EthiopicCalendar</code> using the current time
149      * in the default time zone with the default locale.
150      * @stable ICU 3.4
151      */
152     public EthiopicCalendar() {
153         super();
154     }
155
156     /**
157      * Constructs a <code>EthiopicCalendar</code> based on the current time
158      * in the given time zone with the default locale.
159      *
160      * @param zone The time zone for the new calendar.
161      * @stable ICU 3.4
162      */
163     public EthiopicCalendar(TimeZone zone) {
164         super(zone);
165     }
166
167     /**
168      * Constructs a <code>EthiopicCalendar</code> based on the current time
169      * in the default time zone with the given locale.
170      *
171      * @param aLocale The locale for the new calendar.
172      * @stable ICU 3.4
173      */
174     public EthiopicCalendar(Locale aLocale) {
175         super(aLocale);
176     }
177
178     /**
179      * Constructs a <code>EthiopicCalendar</code> based on the current time
180      * in the default time zone with the given locale.
181      *
182      * @param locale The icu locale for the new calendar.
183      * @stable ICU 3.4
184      */
185     public EthiopicCalendar(ULocale locale) {
186         super(locale);
187     }
188
189     /**
190      * Constructs a <code>EthiopicCalendar</code> based on the current time
191      * in the given time zone with the given locale.
192      *
193      * @param zone The time zone for the new calendar.
194      * @param aLocale The locale for the new calendar.
195      * @stable ICU 3.4
196      */
197     public EthiopicCalendar(TimeZone zone, Locale aLocale) {
198         super(zone, aLocale);
199     }
200     
201     /**
202      * Constructs a <code>EthiopicCalendar</code> based on the current time
203      * in the given time zone with the given locale.
204      *
205      * @param zone The time zone for the new calendar.
206      * @param locale The icu locale for the new calendar.
207      * @stable ICU 3.4
208      */
209     public EthiopicCalendar(TimeZone zone, ULocale locale) {
210         super(zone, locale);
211     }
212     
213     /**
214      * Constructs a <code>EthiopicCalendar</code> with the given date set
215      * in the default time zone with the default locale.
216      *
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.
221      * @stable ICU 3.4
222      */
223     public EthiopicCalendar(int year, int month, int date) {
224         super(year, month, date);
225     }
226
227     /**
228      * Constructs a <code>EthiopicCalendar</code> with the given date set
229      * in the default time zone with the default locale.
230      *
231      * @param date      The date to which the new calendar is set.
232      * @stable ICU 3.4
233      */
234     public EthiopicCalendar(Date date) {
235         super(date);
236     }
237
238     /**
239      * Constructs a <code>EthiopicCalendar</code> with the given date
240      * and time set for the default time zone with the default locale.
241      *
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.
249      * @stable ICU 3.4
250      */
251     public EthiopicCalendar(int year, int month, int date, int hour,
252                             int minute, int second)
253     {
254         super(year, month, date, hour, minute, second);
255     }
256
257     /**
258      * {@inheritDoc}
259      * @stable ICU 3.8
260      */
261     public String getType() {
262         if (isAmeteAlemEra()) {
263             return "ethiopic-amete-alem";
264         }
265         return "ethiopic";
266     }
267
268     /**
269      * Set Alem or Mihret era.
270      *
271      * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
272      * @stable ICU 3.4
273      */
274     public void setAmeteAlemEra(boolean onOff) {
275         eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
276     }
277     
278     /**
279      * Return true if this calendar is set to the Amete Alem era.
280      *
281      * @return true if set to the Amete Alem era.
282      * @stable ICU 3.4
283      */
284     public boolean isAmeteAlemEra() {
285         return (eraType == AMETE_ALEM_ERA);
286     }
287
288     /**
289      * {@inheritDoc}
290      * @internal
291      * @deprecated This API is ICU internal only.
292      */
293     protected int handleGetExtendedYear() {
294         // Ethiopic calendar uses EXTENDED_YEAR aligned to
295         // Amelete Mihret year always.
296         int eyear;
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
302         } else {
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
307             } else {
308                 eyear = internalGet(YEAR, 1) - AMETE_MIHRET_DELTA;
309             }
310         }
311         return eyear;
312     }
313
314     /**
315      * {@inheritDoc}
316      * @internal
317      * @deprecated This API is ICU internal only.
318      */
319     protected void handleComputeFields(int julianDay) {
320         int era, year;
321         int[] fields = new int[3];
322         jdToCE(julianDay, getJDEpochOffset(), fields);
323
324         // fields[0] eyear
325         // fields[1] month
326         // fields[2] day
327
328         if (isAmeteAlemEra()) {
329             era = AMETE_ALEM;
330             year = fields[0] + AMETE_MIHRET_DELTA;
331         } else {
332             if (fields[0] > 0) {
333                 era = AMETE_MIHRET;
334                 year = fields[0];
335             } else {
336                 era = AMETE_ALEM;
337                 year = fields[0] + AMETE_MIHRET_DELTA;
338             }
339         }
340
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]);
347     }
348
349     /**
350      * {@inheritDoc}
351      * @internal
352      * @deprecated This API is ICU internal only.
353      */
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
357         }
358         return super.handleGetLimit(field, limitType);
359     }
360
361     /**
362      * {@inheritDoc}
363      * @internal
364      * @deprecated This API is ICU internal only.
365      */
366     protected int getJDEpochOffset() {
367         return JD_EPOCH_OFFSET_AMETE_MIHRET;
368     }
369
370     /**
371      * Convert an Ethiopic year, month, and day to a Julian day.
372      *
373      * @param year the year
374      * @param month the month
375      * @param date the day
376      *
377      * @draft ICU 3.4 (retain)
378      * @provisional This API might change or be removed in a future release.
379      */
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);
386     }
387 }
388