annotate 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
rev   line source
arajkumar@11038 1 // © 2016 and later: Unicode, Inc. and others.
arajkumar@11038 2 // License & terms of use: http://www.unicode.org/copyright.html
ghb@10550 3 /*
ghb@10550 4 ******************************************************************************
ghb@10550 5 * Copyright (C) 2013, International Business Machines Corporation
ghb@10550 6 * and others. All Rights Reserved.
ghb@10550 7 ******************************************************************************
ghb@10550 8 *
ghb@10550 9 * File DANGICAL.CPP
ghb@10550 10 *****************************************************************************
ghb@10550 11 */
ghb@10550 12
ghb@10550 13 #include "chnsecal.h"
ghb@10550 14 #include "dangical.h"
ghb@10550 15
ghb@10550 16 #if !UCONFIG_NO_FORMATTING
ghb@10550 17
arajkumar@11038 18 #include "gregoimp.h" // Math
arajkumar@11038 19 #include "uassert.h"
arajkumar@11038 20 #include "ucln_in.h"
ghb@10550 21 #include "umutex.h"
ghb@10550 22 #include "unicode/rbtz.h"
ghb@10550 23 #include "unicode/tzrule.h"
ghb@10550 24
ghb@10550 25 // --- The cache --
ghb@10550 26 static icu::TimeZone *gDangiCalendarZoneAstroCalc = NULL;
arajkumar@11038 27 static icu::UInitOnce gDangiCalendarInitOnce = U_INITONCE_INITIALIZER;
ghb@10550 28
ghb@10550 29 /**
ghb@10550 30 * The start year of the Korean traditional calendar (Dan-gi) is the inaugural
ghb@10550 31 * year of Dan-gun (BC 2333).
ghb@10550 32 */
ghb@10550 33 static const int32_t DANGI_EPOCH_YEAR = -2332; // Gregorian year
ghb@10550 34
ghb@10550 35 U_CDECL_BEGIN
ghb@10550 36 static UBool calendar_dangi_cleanup(void) {
ghb@10550 37 if (gDangiCalendarZoneAstroCalc) {
ghb@10550 38 delete gDangiCalendarZoneAstroCalc;
ghb@10550 39 gDangiCalendarZoneAstroCalc = NULL;
ghb@10550 40 }
arajkumar@11038 41 gDangiCalendarInitOnce.reset();
ghb@10550 42 return TRUE;
ghb@10550 43 }
ghb@10550 44 U_CDECL_END
ghb@10550 45
ghb@10550 46 U_NAMESPACE_BEGIN
ghb@10550 47
ghb@10550 48 // Implementation of the DangiCalendar class
ghb@10550 49
ghb@10550 50 //-------------------------------------------------------------------------
ghb@10550 51 // Constructors...
ghb@10550 52 //-------------------------------------------------------------------------
ghb@10550 53
ghb@10550 54 DangiCalendar::DangiCalendar(const Locale& aLocale, UErrorCode& success)
ghb@10550 55 : ChineseCalendar(aLocale, DANGI_EPOCH_YEAR, getDangiCalZoneAstroCalc(), success)
ghb@10550 56 {
ghb@10550 57 }
ghb@10550 58
ghb@10550 59 DangiCalendar::DangiCalendar (const DangiCalendar& other)
ghb@10550 60 : ChineseCalendar(other)
ghb@10550 61 {
ghb@10550 62 }
ghb@10550 63
ghb@10550 64 DangiCalendar::~DangiCalendar()
ghb@10550 65 {
ghb@10550 66 }
ghb@10550 67
ghb@10550 68 Calendar*
ghb@10550 69 DangiCalendar::clone() const
ghb@10550 70 {
ghb@10550 71 return new DangiCalendar(*this);
ghb@10550 72 }
ghb@10550 73
ghb@10550 74 const char *DangiCalendar::getType() const {
ghb@10550 75 return "dangi";
ghb@10550 76 }
ghb@10550 77
ghb@10550 78 /**
ghb@10550 79 * The time zone used for performing astronomical computations for
ghb@10550 80 * Dangi calendar. In Korea various timezones have been used historically
ghb@10550 81 * (cf. http://www.math.snu.ac.kr/~kye/others/lunar.html):
ghb@10550 82 *
ghb@10550 83 * - 1908/04/01: GMT+8
ghb@10550 84 * 1908/04/01 - 1911/12/31: GMT+8.5
ghb@10550 85 * 1912/01/01 - 1954/03/20: GMT+9
ghb@10550 86 * 1954/03/21 - 1961/08/09: GMT+8.5
ghb@10550 87 * 1961/08/10 - : GMT+9
ghb@10550 88 *
ghb@10550 89 * Note that, in 1908-1911, the government did not apply the timezone change
ghb@10550 90 * but used GMT+8. In addition, 1954-1961's timezone change does not affect
ghb@10550 91 * the lunar date calculation. Therefore, the following simpler rule works:
ghb@10550 92 *
ghb@10550 93 * -1911: GMT+8
ghb@10550 94 * 1912-: GMT+9
ghb@10550 95 *
ghb@10550 96 * Unfortunately, our astronomer's approximation doesn't agree with the
ghb@10550 97 * references (http://www.math.snu.ac.kr/~kye/others/lunar.html and
ghb@10550 98 * http://astro.kasi.re.kr/Life/ConvertSolarLunarForm.aspx?MenuID=115)
ghb@10550 99 * in 1897/7/30. So the following ad hoc fix is used here:
ghb@10550 100 *
ghb@10550 101 * -1896: GMT+8
ghb@10550 102 * 1897: GMT+7
ghb@10550 103 * 1898-1911: GMT+8
ghb@10550 104 * 1912- : GMT+9
ghb@10550 105 */
arajkumar@11038 106 static void U_CALLCONV initDangiCalZoneAstroCalc(void) {
arajkumar@11038 107 U_ASSERT(gDangiCalendarZoneAstroCalc == NULL);
arajkumar@11038 108 const UDate millis1897[] = { (UDate)((1897 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
arajkumar@11038 109 const UDate millis1898[] = { (UDate)((1898 - 1970) * 365 * kOneDay) }; // some days of error is not a problem here
arajkumar@11038 110 const UDate millis1912[] = { (UDate)((1912 - 1970) * 365 * kOneDay) }; // this doesn't create an issue for 1911/12/20
arajkumar@11038 111 InitialTimeZoneRule* initialTimeZone = new InitialTimeZoneRule(UNICODE_STRING_SIMPLE("GMT+8"), 8*kOneHour, 0);
arajkumar@11038 112 TimeZoneRule* rule1897 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1897"), 7*kOneHour, 0, millis1897, 1, DateTimeRule::STANDARD_TIME);
arajkumar@11038 113 TimeZoneRule* rule1898to1911 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1898-1911"), 8*kOneHour, 0, millis1898, 1, DateTimeRule::STANDARD_TIME);
arajkumar@11038 114 TimeZoneRule* ruleFrom1912 = new TimeArrayTimeZoneRule(UNICODE_STRING_SIMPLE("Korean 1912-"), 9*kOneHour, 0, millis1912, 1, DateTimeRule::STANDARD_TIME);
arajkumar@11038 115 UErrorCode status = U_ZERO_ERROR;
arajkumar@11038 116 RuleBasedTimeZone* dangiCalZoneAstroCalc = new RuleBasedTimeZone(UNICODE_STRING_SIMPLE("KOREA_ZONE"), initialTimeZone); // adopts initialTimeZone
arajkumar@11038 117 dangiCalZoneAstroCalc->addTransitionRule(rule1897, status); // adopts rule1897
arajkumar@11038 118 dangiCalZoneAstroCalc->addTransitionRule(rule1898to1911, status);
arajkumar@11038 119 dangiCalZoneAstroCalc->addTransitionRule(ruleFrom1912, status);
arajkumar@11038 120 dangiCalZoneAstroCalc->complete(status);
arajkumar@11038 121 if (U_SUCCESS(status)) {
arajkumar@11038 122 gDangiCalendarZoneAstroCalc = dangiCalZoneAstroCalc;
arajkumar@11038 123 } else {
arajkumar@11038 124 delete dangiCalZoneAstroCalc;
arajkumar@11038 125 gDangiCalendarZoneAstroCalc = NULL;
arajkumar@11038 126 }
arajkumar@11038 127 ucln_i18n_registerCleanup(UCLN_I18N_DANGI_CALENDAR, calendar_dangi_cleanup);
arajkumar@11038 128 }
arajkumar@11038 129
ghb@10550 130 const TimeZone* DangiCalendar::getDangiCalZoneAstroCalc(void) const {
arajkumar@11038 131 umtx_initOnce(gDangiCalendarInitOnce, &initDangiCalZoneAstroCalc);
ghb@10550 132 return gDangiCalendarZoneAstroCalc;
ghb@10550 133 }
ghb@10550 134
arajkumar@11038 135
ghb@10550 136 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DangiCalendar)
ghb@10550 137
ghb@10550 138 U_NAMESPACE_END
ghb@10550 139
ghb@10550 140 #endif
ghb@10550 141