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
11package android.icu.util;
12
13import java.util.Date;
14import java.util.Locale;
15
16/**
17 * Implement the Coptic calendar system.
18 * <p>
19 * CopticCalendar usually should be instantiated using
20 * {@link android.icu.util.Calendar#getInstance(ULocale)} passing in a <code>ULocale</code>
21 * with the tag <code>"@calendar=coptic"</code>.</p>
22 *
23 * @see android.icu.util.Calendar
24 */
25public final class CopticCalendar extends CECalendar
26{
27    // jdk1.4.2 serialver
28    private static final long serialVersionUID = 5903818751846742911L;
29
30    /**
31     * Constant for ωογτ / تﻮﺗ,
32     * the 1st month of the Coptic year.
33     */
34    public static final int TOUT = 0;
35
36    /**
37     * Constant for Παοπι / ﻪﺑﺎﺑ,
38     * the 2nd month of the Coptic year.
39     */
40    public static final int BABA = 1;
41
42    /**
43     * Constant for Αθορ / رﻮﺗﺎﻫ,
44     * the 3rd month of the Coptic year.
45     */
46    public static final int HATOR = 2;
47
48    /**
49     * Constant for Χοιακ / ﻚﻬﻴﻛ;,
50     * the 4th month of the Coptic year.
51     */
52    public static final int KIAHK = 3;
53
54    /**
55     * Constant for Τωβι / طﻮﺒﻫ,
56     * the 5th month of the Coptic year.
57     */
58    public static final int TOBA = 4;
59
60    /**
61     * Constant for Μεϣιρ / ﺮﻴﺸﻣأ,
62     * the 6th month of the Coptic year.
63     */
64    public static final int AMSHIR = 5;
65
66    /**
67     * Constant for Παρεμϩατ / تﺎﻬﻣﺮﺑ,
68     * the 7th month of the Coptic year.
69     */
70    public static final int BARAMHAT = 6;
71
72    /**
73     * Constant for Φαρμοθι / هدﻮﻣﺮﺑ,
74     * the 8th month of the Coptic year.
75     */
76    public static final int BARAMOUDA = 7;
77
78    /**
79     * Constant for Παϣαν / ﺲﻨﺸﺑ;,
80     * the 9th month of the Coptic year.
81     */
82    public static final int BASHANS = 8;
83
84    /**
85     * Constant for Παωνι / ﻪﻧؤﻮﺑ,
86     * the 10th month of the Coptic year.
87     */
88    public static final int PAONA = 9;
89
90    /**
91     * Constant for Επηπ / ﺐﻴﺑأ,
92     * the 11th month of the Coptic year.
93     */
94    public static final int EPEP = 10;
95
96    /**
97     * Constant for Μεϲωρη / ىﺮﺴﻣ,
98     * the 12th month of the Coptic year.
99     */
100    public static final int MESRA = 11;
101
102    /**
103     * Constant for Πικογϫι μαβοτ / ﺮﻴﻐﺼﻟاﺮﻬﺸﻟا,
104     * the 13th month of the Coptic year.
105     */
106    public static final int NASIE = 12;
107
108    private static final int JD_EPOCH_OFFSET  = 1824665;
109
110    // Eras
111    private static final int BCE = 0;
112    private static final int CE = 1;
113
114    /**
115     * Constructs a default <code>CopticCalendar</code> using the current time
116     * in the default time zone with the default locale.
117     */
118    public CopticCalendar() {
119        super();
120    }
121
122    /**
123     * Constructs a <code>CopticCalendar</code> based on the current time
124     * in the given time zone with the default locale.
125     *
126     * @param zone The time zone for the new calendar.
127     */
128    public CopticCalendar(TimeZone zone) {
129        super(zone);
130    }
131
132    /**
133     * Constructs a <code>CopticCalendar</code> based on the current time
134     * in the default time zone with the given locale.
135     *
136     * @param aLocale The locale for the new calendar.
137     */
138    public CopticCalendar(Locale aLocale) {
139        super(aLocale);
140    }
141
142    /**
143     * Constructs a <code>CopticCalendar</code> based on the current time
144     * in the default time zone with the given locale.
145     *
146     * @param locale The icu locale for the new calendar.
147     */
148    public CopticCalendar(ULocale locale) {
149        super(locale);
150    }
151
152    /**
153     * Constructs a <code>CopticCalendar</code> based on the current time
154     * in the given time zone with the given locale.
155     *
156     * @param zone The time zone for the new calendar.
157     * @param aLocale The locale for the new calendar.
158     */
159    public CopticCalendar(TimeZone zone, Locale aLocale) {
160        super(zone, aLocale);
161    }
162
163    /**
164     * Constructs a <code>CopticCalendar</code> based on the current time
165     * in the given time zone with the given locale.
166     *
167     * @param zone The time zone for the new calendar.
168     * @param locale The icu locale for the new calendar.
169     */
170    public CopticCalendar(TimeZone zone, ULocale locale) {
171        super(zone, locale);
172    }
173
174    /**
175     * Constructs a <code>CopticCalendar</code> with the given date set
176     * in the default time zone with the default locale.
177     *
178     * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
179     * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
180     *                  The value is 0-based. e.g., 0 for Tout.
181     * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
182     */
183    public CopticCalendar(int year, int month, int date) {
184        super(year, month, date);
185    }
186
187    /**
188     * Constructs a <code>CopticCalendar</code> with the given date set
189     * in the default time zone with the default locale.
190     *
191     * @param date      The date to which the new calendar is set.
192     */
193    public CopticCalendar(Date date) {
194        super(date);
195    }
196
197    /**
198     * Constructs a <code>CopticCalendar</code> with the given date
199     * and time set for the default time zone with the default locale.
200     *
201     * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.
202     * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.
203     *                  The value is 0-based. e.g., 0 for Tout.
204     * @param date      The value used to set the calendar's {@link #DATE DATE} time field.
205     * @param hour      The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.
206     * @param minute    The value used to set the calendar's {@link #MINUTE MINUTE} time field.
207     * @param second    The value used to set the calendar's {@link #SECOND SECOND} time field.
208     */
209    public CopticCalendar(int year, int month, int date, int hour,
210                          int minute, int second) {
211        super(year, month, date, hour, minute, second);
212    }
213
214    /**
215     * {@inheritDoc}
216     */
217    public String getType() {
218        return "coptic";
219    }
220
221    /**
222     * {@inheritDoc}
223     * @deprecated This API is ICU internal only.
224     * @hide original deprecated declaration
225     * @hide draft / provisional / internal are hidden on Android
226     */
227    @Deprecated
228    protected int handleGetExtendedYear() {
229        int eyear;
230        if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
231            eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1
232        } else {
233            // The year defaults to the epoch start, the era to AD
234            int era = internalGet(ERA, CE);
235            if (era == BCE) {
236                eyear = 1 - internalGet(YEAR, 1); // Convert to extended year
237            } else {
238                eyear = internalGet(YEAR, 1); // Default to year 1
239            }
240        }
241        return eyear;
242    }
243
244    /**
245     * {@inheritDoc}
246     * @deprecated This API is ICU internal only.
247     * @hide original deprecated declaration
248     * @hide draft / provisional / internal are hidden on Android
249     */
250    @Deprecated
251    protected void handleComputeFields(int julianDay) {
252        int era, year;
253        int[] fields = new int[3];
254        jdToCE(julianDay, getJDEpochOffset(), fields);
255
256        // fields[0] eyear
257        // fields[1] month
258        // fields[2] day
259
260        if (fields[0] <= 0) {
261            era = BCE;
262            year = 1 - fields[0];
263        } else {
264            era = CE;
265            year = fields[0];
266        }
267
268        internalSet(EXTENDED_YEAR, fields[0]);
269        internalSet(ERA, era);
270        internalSet(YEAR, year);
271        internalSet(MONTH, fields[1]);
272        internalSet(DAY_OF_MONTH, fields[2]);
273        internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);
274    }
275
276    /**
277     * {@inheritDoc}
278     * @deprecated This API is ICU internal only.
279     * @hide original deprecated declaration
280     * @hide draft / provisional / internal are hidden on Android
281     */
282    @Deprecated
283    protected int getJDEpochOffset() {
284        return JD_EPOCH_OFFSET;
285    }
286
287    /**
288     * Convert an Coptic year, month, and day to a Julian day.
289     *
290     * @param year the year
291     * @param month the month
292     * @param date the day
293     * @hide draft / provisional / internal are hidden on Android
294     */
295    // The equivalent operation can be done by public Calendar API.
296    // This API was accidentally marked as @draft, but we have no good
297    // reason to keep this.  For now, we leave it as is, but may be
298    // removed in future.  2008-03-21 yoshito
299    public static int copticToJD(long year, int month, int date) {
300        return ceToJD(year, month, date, JD_EPOCH_OFFSET);
301    }
302}
303
304