]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/util/CopticCalendar.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / util / CopticCalendar.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 Coptic calendar system.\r
15  * <p>\r
16  * CopticCalendar 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=coptic"</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 CopticCalendar extends CECalendar \r
24 {\r
25     // jdk1.4.2 serialver\r
26     private static final long serialVersionUID = 5903818751846742911L;\r
27 \r
28     /** \r
29      * Constant for &#x03c9;&#x03bf;&#x03b3;&#x03c4;/&#x062a;&#xfeee;&#xfe97;,\r
30      * the 1st month of the Coptic year. \r
31      * @stable ICU 3.4\r
32      */\r
33     public static final int TOUT = 0;\r
34 \r
35     /** \r
36      * Constant for &#x03a0;&#x03b1;&#x03bf;&#x03c0;&#x03b9;/&#xfeea;&#xfe91;&#xfe8e;&#xfe91;,\r
37      * the 2nd month of the Coptic year. \r
38      * @stable ICU 3.4\r
39      */\r
40     public static final int BABA = 1;\r
41 \r
42     /** \r
43      * Constant for &#x0391;&#x03b8;&#x03bf;&#x03c1;/&#x0631;&#xfeee;&#xfe97;&#xfe8e;&#xfeeb;,\r
44      * the 3rd month of the Coptic year. \r
45      * @stable ICU 3.4\r
46      */\r
47     public static final int HATOR = 2;\r
48 \r
49     /** \r
50      * Constant for &#x03a7;&#x03bf;&#x03b9;&#x03b1;&#x03ba;/&#xfeda;&#xfeec;&#xfef4;&#xfedb;,\r
51      * the 4th month of the Coptic year. \r
52      * @stable ICU 3.4\r
53      */\r
54     public static final int KIAHK = 3;\r
55 \r
56     /** \r
57      * Constant for &#x03a4;&#x03c9;&#x03b2;&#x03b9;/&#x0637;&#xfeee;&#xfe92;&#xfeeb;,\r
58      * the 5th month of the Coptic year. \r
59      * @stable ICU 3.4\r
60      */\r
61     public static final int TOBA = 4;\r
62 \r
63     /** \r
64      * Constant for &#x039c;&#x03b5;&#x03e3;&#x03b9;&#x03c1;/&#xfeae;&#xfef4;&#xfeb8;&#xfee3;&#x0623;,\r
65      * the 6th month of the Coptic year. \r
66      * @stable ICU 3.4\r
67      */\r
68     public static final int AMSHIR = 5;\r
69 \r
70     /** \r
71      * Constant for &#x03a0;&#x03b1;&#x03c1;&#x03b5;&#x03bc;&#x03e9;&#x03b1;&#x03c4;/&#x062a;&#xfe8e;&#xfeec;&#xfee3;&#xfeae;&#xfe91;,\r
72      * the 7th month of the Coptic year. \r
73      * @stable ICU 3.4\r
74      */\r
75     public static final int BARAMHAT = 6;\r
76 \r
77     /** \r
78      * Constant for &#x03a6;&#x03b1;&#x03c1;&#x03bc;&#x03bf;&#x03b8;&#x03b9;/&#x0647;&#x062f;&#xfeee;&#xfee3;&#xfeae;&#xfe91;, \r
79      * the 8th month of the Coptic year. \r
80      * @stable ICU 3.4\r
81      */\r
82     public static final int BARAMOUDA = 7;\r
83 \r
84     /** \r
85      * Constant for &#x03a0;&#x03b1;&#x03e3;&#x03b1;&#x03bd;/&#xfeb2;&#xfee8;&#xfeb8;&#xfe91;,\r
86      * the 9th month of the Coptic year. \r
87      * @stable ICU 3.4\r
88      */\r
89     public static final int BASHANS = 8;\r
90 \r
91     /** \r
92      * Constant for &#x03a0;&#x03b1;&#x03c9;&#x03bd;&#x03b9;/&#xfeea;&#xfee7;&#x0624;&#xfeee;&#xfe91;,\r
93      * the 10th month of the Coptic year. \r
94      * @stable ICU 3.4\r
95      */\r
96     public static final int PAONA = 9;\r
97 \r
98     /** \r
99      * Constant for &#x0395;&#x03c0;&#x03b7;&#x03c0;/&#xfe90;&#xfef4;&#xfe91;&#x0623;,\r
100      * the 11th month of the Coptic year. \r
101      * @stable ICU 3.4\r
102      */\r
103     public static final int EPEP = 10;\r
104 \r
105     /** \r
106      * Constant for &#x039c;&#x03b5;&#x03f2;&#x03c9;&#x03c1;&#x03b7;/&#x0649;&#xfeae;&#xfeb4;&#xfee3;,\r
107      * the 12th month of the Coptic year. \r
108      * @stable ICU 3.4\r
109      */\r
110     public static final int MESRA = 11;\r
111 \r
112     /** \r
113      * Constant for &#x03a0;&#x03b9;&#x03ba;&#x03bf;&#x03b3;&#x03eb;&#x03b9;\r
114      * &#x03bc;&#x03b1;&#x03b2;&#x03bf;&#x03c4;/&#xfeae;&#xfef4;&#xfed0;&#xfebc;&#xfedf;&#x0627;\r
115      * &#xfeae;&#xfeec;&#xfeb8;&#xfedf;&#x0627;,\r
116      * the 13th month of the Coptic year. \r
117      * @stable ICU 3.4\r
118      */\r
119     public static final int NASIE = 12;\r
120   \r
121     private static final int JD_EPOCH_OFFSET  = 1824665;\r
122 \r
123     // Eras\r
124     private static final int BCE = 0;\r
125     private static final int CE = 1;\r
126 \r
127     /**\r
128      * Constructs a default <code>CopticCalendar</code> using the current time\r
129      * in the default time zone with the default locale.\r
130      * @stable ICU 3.4\r
131      */\r
132     public CopticCalendar() {\r
133         super();\r
134     }\r
135 \r
136     /**\r
137      * Constructs a <code>CopticCalendar</code> based on the current time\r
138      * in the given time zone with the default locale.\r
139      *\r
140      * @param zone The time zone for the new calendar.\r
141      * @stable ICU 3.4\r
142      */\r
143     public CopticCalendar(TimeZone zone) {\r
144         super(zone);\r
145     }\r
146 \r
147     /**\r
148      * Constructs a <code>CopticCalendar</code> based on the current time\r
149      * in the default time zone with the given locale.\r
150      *\r
151      * @param aLocale The locale for the new calendar.\r
152      * @stable ICU 3.4\r
153      */\r
154     public CopticCalendar(Locale aLocale) {\r
155         super(aLocale);\r
156     }\r
157 \r
158     /**\r
159      * Constructs a <code>CopticCalendar</code> based on the current time\r
160      * in the default time zone with the given locale.\r
161      *\r
162      * @param locale The icu locale for the new calendar.\r
163      * @stable ICU 3.4\r
164      */\r
165     public CopticCalendar(ULocale locale) {\r
166         super(locale);\r
167     }\r
168 \r
169     /**\r
170      * Constructs a <code>CopticCalendar</code> based on the current time\r
171      * in the given time zone with the given locale.\r
172      *\r
173      * @param zone The time zone for the new calendar.\r
174      * @param aLocale The locale for the new calendar.\r
175      * @stable ICU 3.4\r
176      */\r
177     public CopticCalendar(TimeZone zone, Locale aLocale) {\r
178         super(zone, aLocale);\r
179     }\r
180     \r
181     /**\r
182      * Constructs a <code>CopticCalendar</code> based on the current time\r
183      * in the given time zone with the given locale.\r
184      *\r
185      * @param zone The time zone for the new calendar.\r
186      * @param locale The icu locale for the new calendar.\r
187      * @stable ICU 3.4\r
188      */\r
189     public CopticCalendar(TimeZone zone, ULocale locale) {\r
190         super(zone, locale);\r
191     }\r
192     \r
193     /**\r
194      * Constructs a <code>CopticCalendar</code> with the given date set\r
195      * in the default time zone with the default locale.\r
196      *\r
197      * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.\r
198      * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.\r
199      *                  The value is 0-based. e.g., 0 for Tout.\r
200      * @param date      The value used to set the calendar's {@link #DATE DATE} time field.\r
201      * @stable ICU 3.4\r
202      */\r
203     public CopticCalendar(int year, int month, int date) {\r
204         super(year, month, date);\r
205     }\r
206 \r
207     /**\r
208      * Constructs a <code>CopticCalendar</code> with the given date set\r
209      * in the default time zone with the default locale.\r
210      *\r
211      * @param date      The date to which the new calendar is set.\r
212      * @stable ICU 3.4\r
213      */\r
214     public CopticCalendar(Date date) {\r
215         super(date);\r
216     }\r
217 \r
218     /**\r
219      * Constructs a <code>CopticCalendar</code> with the given date\r
220      * and time set for the default time zone with the default locale.\r
221      *\r
222      * @param year      The value used to set the calendar's {@link #YEAR YEAR} time field.\r
223      * @param month     The value used to set the calendar's {@link #MONTH MONTH} time field.\r
224      *                  The value is 0-based. e.g., 0 for Tout.\r
225      * @param date      The value used to set the calendar's {@link #DATE DATE} time field.\r
226      * @param hour      The value used to set the calendar's {@link #HOUR_OF_DAY HOUR_OF_DAY} time field.\r
227      * @param minute    The value used to set the calendar's {@link #MINUTE MINUTE} time field.\r
228      * @param second    The value used to set the calendar's {@link #SECOND SECOND} time field.\r
229      * @stable ICU 3.4\r
230      */\r
231     public CopticCalendar(int year, int month, int date, int hour,\r
232                           int minute, int second) {\r
233         super(year, month, date, hour, minute, second);\r
234     }\r
235 \r
236     /**\r
237      * {@inheritDoc}\r
238      * @stable ICU 3.8\r
239      */\r
240     public String getType() {\r
241         return "coptic";\r
242     }\r
243 \r
244     /**\r
245      * {@inheritDoc}\r
246      * @internal\r
247      * @deprecated This API is ICU internal only.\r
248      */\r
249     protected int handleGetExtendedYear() {\r
250         int eyear;\r
251         if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {\r
252             eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1\r
253         } else {\r
254             // The year defaults to the epoch start, the era to AD\r
255             int era = internalGet(ERA, CE);\r
256             if (era == BCE) {\r
257                 eyear = 1 - internalGet(YEAR, 1); // Convert to extended year\r
258             } else {\r
259                 eyear = internalGet(YEAR, 1); // Default to year 1\r
260             }\r
261         }\r
262         return eyear;\r
263     }\r
264 \r
265     /**\r
266      * {@inheritDoc}\r
267      * @internal\r
268      * @deprecated This API is ICU internal only.\r
269      */\r
270     protected void handleComputeFields(int julianDay) {\r
271         int era, year;\r
272         int[] fields = new int[3];\r
273         jdToCE(julianDay, getJDEpochOffset(), fields);\r
274 \r
275         // fields[0] eyear\r
276         // fields[1] month\r
277         // fields[2] day\r
278 \r
279         if (fields[0] <= 0) {\r
280             era = BCE;\r
281             year = 1 - fields[0];\r
282         } else {\r
283             era = CE;\r
284             year = fields[0];\r
285         }\r
286 \r
287         internalSet(EXTENDED_YEAR, fields[0]);\r
288         internalSet(ERA, era);\r
289         internalSet(YEAR, year);\r
290         internalSet(MONTH, fields[1]);\r
291         internalSet(DAY_OF_MONTH, fields[2]);\r
292         internalSet(DAY_OF_YEAR, (30 * fields[1]) + fields[2]);\r
293     }\r
294 \r
295     /**\r
296      * {@inheritDoc}\r
297      * @internal\r
298      * @deprecated This API is ICU internal only.\r
299      */\r
300     protected int getJDEpochOffset() {\r
301         return JD_EPOCH_OFFSET;\r
302     }\r
303 \r
304     /**\r
305      * Convert an Coptic year, month, and day to a Julian day.\r
306      *\r
307      * @param year the year\r
308      * @param month the month\r
309      * @param date the day\r
310      * @draft ICU 3.4 (retain)\r
311      * @provisional This API might change or be removed in a future release.\r
312      */\r
313     // The equivalent operation can be done by public Calendar API.\r
314     // This API was accidentally marked as @draft, but we have no good\r
315     // reason to keep this.  For now, we leave it as is, but may be\r
316     // removed in future.  2008-03-21 yoshito\r
317     public static int copticToJD(long year, int month, int date) {\r
318         return ceToJD(year, month, date, JD_EPOCH_OFFSET);\r
319     }\r
320 }\r
321 \r