• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2016 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 /*
5  *******************************************************************************
6  * Copyright (C) 2005-2016, International Business Machines Corporation and
7  * others. All Rights Reserved.
8  *******************************************************************************
9  */
10 
11 package ohos.global.icu.util;
12 
13 import java.util.Date;
14 import java.util.Locale;
15 
16 import ohos.global.icu.impl.CalendarUtil;
17 import ohos.global.icu.util.ULocale.Category;
18 
19 /**
20  * Implement the Ethiopic calendar system.
21  * <p>
22  * EthiopicCalendar usually should be instantiated using
23  * {@link ohos.global.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
24  * with the tag <code>"@calendar=ethiopic"</code>.</p>
25  *
26  * @see ohos.global.icu.util.Calendar
27  */
28 public final class EthiopicCalendar extends CECalendar
29 {
30     //jdk1.4.2 serialver
31     private static final long serialVersionUID = -2438495771339315608L;
32 
33     /**
34      * Constant for መስከረም, the 1st month of the Ethiopic year.
35      */
36     public static final int MESKEREM = 0;
37 
38     /**
39      * Constant for ጥቅምት, the 2nd month of the Ethiopic year.
40      */
41     public static final int TEKEMT = 1;
42 
43     /**
44      * Constant for ኅዳር, the 3rd month of the Ethiopic year.
45      */
46     public static final int HEDAR = 2;
47 
48     /**
49      * Constant for ታኅሣሥ, the 4th month of the Ethiopic year.
50      */
51     public static final int TAHSAS = 3;
52 
53     /**
54      * Constant for ጥር, the 5th month of the Ethiopic year.
55      */
56     public static final int TER = 4;
57 
58     /**
59      * Constant for የካቲት, the 6th month of the Ethiopic year.
60      */
61     public static final int YEKATIT = 5;
62 
63     /**
64      * Constant for መጋቢት, the 7th month of the Ethiopic year.
65      */
66     public static final int MEGABIT = 6;
67 
68     /**
69      * Constant for ሚያዝያ, the 8th month of the Ethiopic year.
70      */
71     public static final int MIAZIA = 7;
72 
73     /**
74      * Constant for ግንቦት, the 9th month of the Ethiopic year.
75      */
76     public static final int GENBOT = 8;
77 
78     /**
79      * Constant for ሰኔ, the 10th month of the Ethiopic year.
80      */
81     public static final int SENE = 9;
82 
83     /**
84      * Constant for ሐምሌ, the 11th month of the Ethiopic year.
85      */
86     public static final int HAMLE = 10;
87 
88     /**
89      * Constant for ነሐሴ, the 12th month of the Ethiopic year.
90      */
91     public static final int NEHASSE = 11;
92 
93     /**
94      * Constant for ጳጉሜን, the 13th month of the Ethiopic year.
95      */
96     public static final int PAGUMEN = 12;
97 
98     // Up until the end of the 19th century the prevailant convention was to
99     // reference the Ethiopic Calendar from the creation of the world,
100     // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d
101     // (Amete Alem 5500 BC).  As Ethiopia modernized the reference epoch from
102     // the birth of Christ (\u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275)
103     // began to displace the creation of the
104     // world reference point.  However, years before the birth of Christ are
105     // still referenced in the creation of the world system.
106     // Thus -100 \u12d3/\u121d
107     // would be rendered as 5400  \u12d3/\u12d3.
108     //
109     // The creation of the world in Ethiopic cannon was
110     // Meskerem 1, -5500  \u12d3/\u121d 00:00:00
111     // applying the birth of Christ reference and Ethiopian time conventions.  This is
112     // 6 hours less than the Julian epoch reference point (noon).  In Gregorian
113     // the date and time was July 18th -5493 BC 06:00 AM.
114 
115     // Julian Days relative to the
116     // \u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275 epoch
117     // Note: we no longer use this constant
118     //private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
119 
120     // Julian Days relative to the
121     // \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d epoch
122     private static final int JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
123 
124     // The delta between Amete Alem 1 and Amete Mihret 1
125     // AA 5501 = AM 1
126     private static final int AMETE_MIHRET_DELTA = 5500;
127 
128     // Eras
129     private static final int AMETE_ALEM = 0;
130     private static final int AMETE_MIHRET = 1;
131 
132     // Era mode.  When eraType is AMETE_ALEM_ERA,
133     // Amete Mihret won't be used for the ERA field.
134     private static final int AMETE_MIHRET_ERA = 0;
135     private static final int AMETE_ALEM_ERA = 1;
136 
137     private int eraType = AMETE_MIHRET_ERA;
138 
139     /**
140      * Constructs a default <code>EthiopicCalendar</code> using the current time
141      * in the default time zone with the default locale.
142      */
EthiopicCalendar()143     public EthiopicCalendar() {
144         this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
145     }
146 
147     /**
148      * Constructs a <code>EthiopicCalendar</code> based on the current time
149      * in the given time zone with the default locale.
150      *
151      * @param zone The time zone for the new calendar.
152      */
EthiopicCalendar(TimeZone zone)153     public EthiopicCalendar(TimeZone zone) {
154         this(zone, ULocale.getDefault(Category.FORMAT));
155     }
156 
157     /**
158      * Constructs a <code>EthiopicCalendar</code> based on the current time
159      * in the default time zone with the given locale.
160      *
161      * @param aLocale The locale for the new calendar.
162      */
EthiopicCalendar(Locale aLocale)163     public EthiopicCalendar(Locale aLocale) {
164         this(TimeZone.getDefault(), aLocale);
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 locale The icu locale for the new calendar.
172      */
EthiopicCalendar(ULocale locale)173     public EthiopicCalendar(ULocale locale) {
174         this(TimeZone.getDefault(), locale);
175     }
176 
177     /**
178      * Constructs a <code>EthiopicCalendar</code> based on the current time
179      * in the given time zone with the given locale.
180      *
181      * @param zone The time zone for the new calendar.
182      * @param aLocale The locale for the new calendar.
183      */
EthiopicCalendar(TimeZone zone, Locale aLocale)184     public EthiopicCalendar(TimeZone zone, Locale aLocale) {
185         this(zone, ULocale.forLocale(aLocale));
186     }
187 
188     /**
189      * Constructs a <code>EthiopicCalendar</code> based on the current time
190      * in the given time zone with the given locale.
191      *
192      * @param zone The time zone for the new calendar.
193      * @param locale The icu locale for the new calendar.
194      */
EthiopicCalendar(TimeZone zone, ULocale locale)195     public EthiopicCalendar(TimeZone zone, ULocale locale) {
196         super(zone, locale);
197         setCalcTypeForLocale(locale);
198     }
199 
200     /**
201      * Constructs a <code>EthiopicCalendar</code> with the given date set
202      * in the default time zone with the default locale.
203      *
204      * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
205      * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
206      *                  The value is 0-based. e.g., 0 for Meskerem.
207      * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
208      */
EthiopicCalendar(int year, int month, int date)209     public EthiopicCalendar(int year, int month, int date) {
210         super(year, month, date);
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 date      The date to which the new calendar is set.
218      */
EthiopicCalendar(Date date)219     public EthiopicCalendar(Date date) {
220         super(date);
221     }
222 
223     /**
224      * Constructs a <code>EthiopicCalendar</code> with the given date
225      * and time set for the default time zone with the default locale.
226      *
227      * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
228      * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
229      *                  The value is 0-based. e.g., 0 for Meskerem.
230      * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
231      * @param hour      The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
232      * @param minute    The value used to set the calendar's {@link #MINUTE MINUTE} time field.
233      * @param second    The value used to set the calendar's {@link #SECOND SECOND} time field.
234      */
EthiopicCalendar(int year, int month, int date, int hour, int minute, int second)235     public EthiopicCalendar(int year, int month, int date, int hour,
236                             int minute, int second)
237     {
238         super(year, month, date, hour, minute, second);
239     }
240 
241     /**
242      * {@inheritDoc}
243      */
getType()244     public String getType() {
245         if (isAmeteAlemEra()) {
246             return "ethiopic-amete-alem";
247         }
248         return "ethiopic";
249     }
250 
251     /**
252      * Set Alem or Mihret era.
253      *
254      * @param onOff Set Amete Alem era if true, otherwise set Amete Mihret era.
255      */
setAmeteAlemEra(boolean onOff)256     public void setAmeteAlemEra(boolean onOff) {
257         eraType = onOff ? AMETE_ALEM_ERA : AMETE_MIHRET_ERA;
258     }
259 
260     /**
261      * Return true if this calendar is set to the Amete Alem era.
262      *
263      * @return true if set to the Amete Alem era.
264      */
isAmeteAlemEra()265     public boolean isAmeteAlemEra() {
266         return (eraType == AMETE_ALEM_ERA);
267     }
268 
269     /**
270      * {@inheritDoc}
271      * @deprecated This API is ICU internal only.
272      * @hide draft / provisional / internal are hidden on OHOS
273      */
274     @Deprecated
handleGetExtendedYear()275     protected int handleGetExtendedYear() {
276         // Ethiopic calendar uses EXTENDED_YEAR aligned to
277         // Amelete Mihret year always.
278         int eyear;
279         if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
280             eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1
281         } else if (isAmeteAlemEra()){
282             eyear = internalGet(YEAR, 1 + AMETE_MIHRET_DELTA)
283                     - AMETE_MIHRET_DELTA; // Default to year 1 of Amelete Mihret
284         } else {
285             // The year defaults to the epoch start, the era to AMETE_MIHRET
286             int era = internalGet(ERA, AMETE_MIHRET);
287             if (era == AMETE_MIHRET) {
288                 eyear = internalGet(YEAR, 1); // Default to year 1
289             } else {
290                 eyear = internalGet(YEAR, 1) - AMETE_MIHRET_DELTA;
291             }
292         }
293         return eyear;
294     }
295 
296     /**
297      * {@inheritDoc}
298      * @deprecated This API is ICU internal only.
299      * @hide draft / provisional / internal are hidden on OHOS
300      */
301     @Deprecated
handleComputeFields(int julianDay)302     protected void handleComputeFields(int julianDay) {
303         int era, year;
304         int[] fields = new int[3];
305         jdToCE(julianDay, getJDEpochOffset(), fields);
306 
307         // fields[0] eyear
308         // fields[1] month
309         // fields[2] day
310 
311         if (isAmeteAlemEra()) {
312             era = AMETE_ALEM;
313             year = fields[0] + AMETE_MIHRET_DELTA;
314         } else {
315             if (fields[0] > 0) {
316                 era = AMETE_MIHRET;
317                 year = fields[0];
318             } else {
319                 era = AMETE_ALEM;
320                 year = fields[0] + AMETE_MIHRET_DELTA;
321             }
322         }
323 
324         internalSet(EXTENDED_YEAR, fields[0]);
325         internalSet(ERA, era);
326         internalSet(YEAR, year);
327         internalSet(MONTH, fields[1]);
328         internalSet(DAY_OF_MONTH, fields[2]);
329         internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);
330     }
331 
332     /**
333      * {@inheritDoc}
334      * @deprecated This API is ICU internal only.
335      * @hide draft / provisional / internal are hidden on OHOS
336      */
337     @Deprecated
handleGetLimit(int field, int limitType)338     protected int handleGetLimit(int field, int limitType) {
339         if (isAmeteAlemEra() && field == ERA) {
340             return 0; // Only one era in this mode, era is always 0
341         }
342         return super.handleGetLimit(field, limitType);
343     }
344 
345     /**
346      * {@inheritDoc}
347      * @deprecated This API is ICU internal only.
348      * @hide draft / provisional / internal are hidden on OHOS
349      */
350     @Deprecated
getJDEpochOffset()351     protected int getJDEpochOffset() {
352         return JD_EPOCH_OFFSET_AMETE_MIHRET;
353     }
354 
355     /**
356      * Convert an Ethiopic year, month, and day to a Julian day.
357      *
358      * @param year the year
359      * @param month the month
360      * @param date the day
361      *
362      * @hide draft / provisional / internal are hidden on OHOS
363      */
364     // The equivalent operation can be done by public Calendar API.
365     // This API was accidentally marked as @draft, but we have no good
366     // reason to keep this.  For now, we leave it as is, but may be
367     // removed in future.  2008-03-21 yoshito
EthiopicToJD(long year, int month, int date)368     public static int EthiopicToJD(long year, int month, int date) {
369         return ceToJD(year, month, date, JD_EPOCH_OFFSET_AMETE_MIHRET);
370     }
371 
372     /**
373      * set type based on locale
374      */
setCalcTypeForLocale(ULocale locale)375     private void setCalcTypeForLocale(ULocale locale) {
376         String localeCalType = CalendarUtil.getCalendarType(locale);
377         if("ethiopic-amete-alem".equals(localeCalType)) {
378             setAmeteAlemEra(true);
379         } else {
380             setAmeteAlemEra(false); // default - Amete Mihret
381         }
382     }
383 }
384 
385