comparison modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/i18n/dangical.cpp @ 11038:20a8447c71c6

8207159: Update ICU to version 62.1 Reviewed-by: mbilla, kcr, ghb
author arajkumar
date Fri, 24 Aug 2018 15:06:40 +0530
parents fee4ef5c87df
children
comparison
equal deleted inserted replaced
0:92200433ca11 1:5966bbc33558
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
1 /* 3 /*
2 ****************************************************************************** 4 ******************************************************************************
3 * Copyright (C) 2013, International Business Machines Corporation 5 * Copyright (C) 2013, International Business Machines Corporation
4 * and others. All Rights Reserved. 6 * and others. All Rights Reserved.
5 ****************************************************************************** 7 ******************************************************************************
11 #include "chnsecal.h" 13 #include "chnsecal.h"
12 #include "dangical.h" 14 #include "dangical.h"
13 15
14 #if !UCONFIG_NO_FORMATTING 16 #if !UCONFIG_NO_FORMATTING
15 17
18 #include "gregoimp.h" // Math
19 #include "uassert.h"
20 #include "ucln_in.h"
16 #include "umutex.h" 21 #include "umutex.h"
17 #include "gregoimp.h" // Math
18 #include "unicode/rbtz.h" 22 #include "unicode/rbtz.h"
19 #include "unicode/tzrule.h" 23 #include "unicode/tzrule.h"
20 #include "ucln_in.h"
21 24
22 // --- The cache -- 25 // --- The cache --
23 static UMutex dangiLock = U_MUTEX_INITIALIZER;
24 static icu::TimeZone *gDangiCalendarZoneAstroCalc = NULL; 26 static icu::TimeZone *gDangiCalendarZoneAstroCalc = NULL;
25 static UBool gDangiCalendarZoneAstroCalcInitialized = FALSE; 27 static icu::UInitOnce gDangiCalendarInitOnce = U_INITONCE_INITIALIZER;
26 28
27 /** 29 /**
28 * The start year of the Korean traditional calendar (Dan-gi) is the inaugural 30 * The start year of the Korean traditional calendar (Dan-gi) is the inaugural
29 * year of Dan-gun (BC 2333). 31 * year of Dan-gun (BC 2333).
30 */ 32 */
34 static UBool calendar_dangi_cleanup(void) { 36 static UBool calendar_dangi_cleanup(void) {
35 if (gDangiCalendarZoneAstroCalc) { 37 if (gDangiCalendarZoneAstroCalc) {
36 delete gDangiCalendarZoneAstroCalc; 38 delete gDangiCalendarZoneAstroCalc;
37 gDangiCalendarZoneAstroCalc = NULL; 39 gDangiCalendarZoneAstroCalc = NULL;
38 } 40 }
39 gDangiCalendarZoneAstroCalcInitialized = FALSE; 41 gDangiCalendarInitOnce.reset();
40 return TRUE; 42 return TRUE;
41 } 43 }
42 U_CDECL_END 44 U_CDECL_END
43 45
44 U_NAMESPACE_BEGIN 46 U_NAMESPACE_BEGIN
99 * -1896: GMT+8 101 * -1896: GMT+8
100 * 1897: GMT+7 102 * 1897: GMT+7
101 * 1898-1911: GMT+8 103 * 1898-1911: GMT+8
102 * 1912- : GMT+9 104 * 1912- : GMT+9
103 */ 105 */
106 static void U_CALLCONV initDangiCalZoneAstroCalc(void) {
107 U_ASSERT(gDangiCalendarZoneAstroCalc == NULL);
108 const UDate millis1897[] = { (UDate)((1897 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
109 const UDate millis1898[] = { (UDate)((1898 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
110 const UDate millis1912[] = { (UDate)((1912 - 1970) * 365 * kOneDay) }; // this doesn't create an issue for 1911/12/20
111 InitialTimeZoneRule* initialTimeZone = new InitialTimeZoneRule(UNICODE_STRING_SIMPLE("GMT+8"), 8*kOneHour, 0);
112 TimeZoneRule* rule1897 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1897"), 7*kOneHour, 0, millis1897, 1, DateTimeRule::STANDARD_TIME);
113 TimeZoneRule* rule1898to1911 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1898-1911"), 8*kOneHour, 0, millis1898, 1, DateTimeRule::STANDARD_TIME);
114 TimeZoneRule* ruleFrom1912 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1912-"), 9*kOneHour, 0, millis1912, 1, DateTimeRule::STANDARD_TIME);
115 UErrorCode status = U_ZERO_ERROR;
116 RuleBasedTimeZone* dangiCalZoneAstroCalc = new RuleBasedTimeZone(UNICODE_STRING_SIMPLE("KOREA_ZONE"), initialTimeZone); // adopts initialTimeZone
117 dangiCalZoneAstroCalc->addTransitionRule(rule1897, status); // adopts rule1897
118 dangiCalZoneAstroCalc->addTransitionRule(rule1898to1911, status);
119 dangiCalZoneAstroCalc->addTransitionRule(ruleFrom1912, status);
120 dangiCalZoneAstroCalc->complete(status);
121 if (U_SUCCESS(status)) {
122 gDangiCalendarZoneAstroCalc = dangiCalZoneAstroCalc;
123 } else {
124 delete dangiCalZoneAstroCalc;
125 gDangiCalendarZoneAstroCalc = NULL;
126 }
127 ucln_i18n_registerCleanup(UCLN_I18N_DANGI_CALENDAR, calendar_dangi_cleanup);
128 }
129
104 const TimeZone* DangiCalendar::getDangiCalZoneAstroCalc(void) const { 130 const TimeZone* DangiCalendar::getDangiCalZoneAstroCalc(void) const {
105 UBool initialized; 131 umtx_initOnce(gDangiCalendarInitOnce, &initDangiCalZoneAstroCalc);
106 UMTX_CHECK(&dangiLock, gDangiCalendarZoneAstroCalcInitialized, initialized);
107 if (!initialized) {
108 umtx_lock(&dangiLock);
109 {
110 if (!gDangiCalendarZoneAstroCalcInitialized) {
111 const UDate millis1897[] = { (UDate)((1897 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
112 const UDate millis1898[] = { (UDate)((1898 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
113 const UDate millis1912[] = { (UDate)((1912 - 1970) * 365 * kOneDay) }; // this doesn't create an issue for 1911/12/20
114 InitialTimeZoneRule* initialTimeZone = new InitialTimeZoneRule(UNICODE_STRING_SIMPLE("GMT+8"), 8*kOneHour, 0);
115 TimeZoneRule* rule1897 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1897"), 7*kOneHour, 0, millis1897, 1, DateTimeRule::STANDARD_TIME);
116 TimeZoneRule* rule1898to1911 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1898-1911"), 8*kOneHour, 0, millis1898, 1, DateTimeRule::STANDARD_TIME);
117 TimeZoneRule* ruleFrom1912 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1912-"), 9*kOneHour, 0, millis1912, 1, DateTimeRule::STANDARD_TIME);
118 UErrorCode status = U_ZERO_ERROR;
119 RuleBasedTimeZone* dangiCalZoneAstroCalc = new RuleBasedTimeZone(UNICODE_STRING_SIMPLE("KOREA_ZONE"), initialTimeZone); // adopts initialTimeZone
120 dangiCalZoneAstroCalc->addTransitionRule(rule1897, status); // adopts rule1897
121 dangiCalZoneAstroCalc->addTransitionRule(rule1898to1911, status);
122 dangiCalZoneAstroCalc->addTransitionRule(ruleFrom1912, status);
123 dangiCalZoneAstroCalc->complete(status);
124 if (U_SUCCESS(status)) {
125 gDangiCalendarZoneAstroCalc = dangiCalZoneAstroCalc;
126 } else {
127 delete dangiCalZoneAstroCalc;
128 gDangiCalendarZoneAstroCalc = NULL;
129 }
130 gDangiCalendarZoneAstroCalcInitialized = TRUE;
131 ucln_i18n_registerCleanup(UCLN_I18N_DANGI_CALENDAR, calendar_dangi_cleanup);
132 }
133 }
134 umtx_unlock(&dangiLock);
135 }
136 return gDangiCalendarZoneAstroCalc; 132 return gDangiCalendarZoneAstroCalc;
137 } 133 }
134
138 135
139 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DangiCalendar) 136 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DangiCalendar)
140 137
141 U_NAMESPACE_END 138 U_NAMESPACE_END
142 139