]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/DangiCalendar.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / util / DangiCalendar.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2012, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.util;
8
9 import java.util.Date;
10
11 import com.ibm.icu.util.ULocale.Category;
12
13 /**
14  * <code>DangiCalendar</code> is a concrete subclass of {@link Calendar}
15  * that implements a traditional Korean calendar.
16  * 
17  * @internal
18  * @deprecated This API is ICU internal only.
19  */
20 public class DangiCalendar extends ChineseCalendar {
21
22     private static final long serialVersionUID = 8156297445349501985L;
23
24     /**
25      * The start year of the Korean traditional calendar (Dan-gi) is the inaugural
26      * year of Dan-gun (BC 2333).
27      */
28     private static final int DANGI_EPOCH_YEAR = -2332;
29
30     /**
31      * The time zone used for performing astronomical computations for
32      * Dangi calendar. In Korea various timezones have been used historically 
33      * (cf. http://www.math.snu.ac.kr/~kye/others/lunar.html): 
34      *  
35      *            - 1908/04/01: GMT+8 
36      * 1908/04/01 - 1911/12/31: GMT+8.5 
37      * 1912/01/01 - 1954/03/20: GMT+9 
38      * 1954/03/21 - 1961/08/09: GMT+8.5 
39      * 1961/08/10 -           : GMT+9 
40      *  
41      * Note that, in 1908-1911, the government did not apply the timezone change 
42      * but used GMT+8. In addition, 1954-1961's timezone change does not affect 
43      * the lunar date calculation. Therefore, the following simpler rule works: 
44      *   
45      * -1911: GMT+8 
46      * 1912-: GMT+9 
47      *  
48      * Unfortunately, our astronomer's approximation doesn't agree with the 
49      * references (http://www.math.snu.ac.kr/~kye/others/lunar.html and 
50      * http://astro.kasi.re.kr/Life/ConvertSolarLunarForm.aspx?MenuID=115) 
51      * in 1897/7/30. So the following ad hoc fix is used here: 
52      *  
53      *     -1896: GMT+8 
54      *      1897: GMT+7 
55      * 1898-1911: GMT+8 
56      * 1912-    : GMT+9 
57      */
58     private static final TimeZone KOREA_ZONE;
59
60     static {
61         InitialTimeZoneRule initialTimeZone = new InitialTimeZoneRule("GMT+8", 8 * ONE_HOUR, 0);
62         long[] millis1897 = { (1897 - 1970) * 365L * ONE_DAY }; // some days of error is not a problem here
63         long[] millis1898 = { (1898 - 1970) * 365L * ONE_DAY }; // some days of error is not a problem here
64         long[] millis1912 = { (1912 - 1970) * 365L * ONE_DAY }; // this doesn't create an issue for 1911/12/20
65         TimeZoneRule rule1897 = new TimeArrayTimeZoneRule("Korean 1897", 7 * ONE_HOUR, 0, millis1897,
66                 DateTimeRule.STANDARD_TIME);
67         TimeZoneRule rule1898to1911 = new TimeArrayTimeZoneRule("Korean 1898-1911", 8 * ONE_HOUR, 0, millis1898,
68                 DateTimeRule.STANDARD_TIME);
69         TimeZoneRule ruleFrom1912 = new TimeArrayTimeZoneRule("Korean 1912-", 9 * ONE_HOUR, 0, millis1912,
70                 DateTimeRule.STANDARD_TIME);
71
72         RuleBasedTimeZone tz = new RuleBasedTimeZone("KOREA_ZONE", initialTimeZone);
73         tz.addTransitionRule(rule1897);
74         tz.addTransitionRule(rule1898to1911);
75         tz.addTransitionRule(ruleFrom1912);
76         tz.freeze();
77         KOREA_ZONE = tz;
78     };
79
80     /**
81      * Construct a <code>DangiCalendar</code> with the default time zone and locale.
82      * 
83      * @internal
84      * @deprecated This API is ICU internal only.
85      */
86     public DangiCalendar() {
87         this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
88     }
89
90     /**
91      * Construct a <code>DangiCalendar</code> with the give date set in the default time zone
92      * with the default locale.
93      * @param date The date to which the new calendar is set.
94      * 
95      * @internal
96      * @deprecated This API is ICU internal only.
97      */
98     public DangiCalendar(Date date) {
99         this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT));
100         setTime(date);
101     }
102
103     /**
104      * Construct a <code>DangiCalendar</code>  based on the current time
105      * with the given time zone with the given locale.
106      * @param zone the given time zone
107      * @param locale the given locale
108      * 
109      * @internal
110      * @deprecated This API is ICU internal only.
111      */
112     public DangiCalendar(TimeZone zone, ULocale locale) {
113         super(zone, locale, DANGI_EPOCH_YEAR, KOREA_ZONE);
114     }
115
116     /**
117      * {@inheritDoc}
118      * 
119      * @internal
120      * @deprecated This API is ICU internal only.
121      */
122     public String getType() {
123         return "dangi";
124     }
125 }