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