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