1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2007-2014, International Business Machines Corporation
6*0e209d39SAndroid Build Coastguard Worker * and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker * File CHNSECAL.CPP
10*0e209d39SAndroid Build Coastguard Worker *
11*0e209d39SAndroid Build Coastguard Worker * Modification History:
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker * Date Name Description
14*0e209d39SAndroid Build Coastguard Worker * 9/18/2007 ajmacher ported from java ChineseCalendar
15*0e209d39SAndroid Build Coastguard Worker *****************************************************************************
16*0e209d39SAndroid Build Coastguard Worker */
17*0e209d39SAndroid Build Coastguard Worker
18*0e209d39SAndroid Build Coastguard Worker #include "chnsecal.h"
19*0e209d39SAndroid Build Coastguard Worker
20*0e209d39SAndroid Build Coastguard Worker #include <cstdint>
21*0e209d39SAndroid Build Coastguard Worker
22*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
23*0e209d39SAndroid Build Coastguard Worker
24*0e209d39SAndroid Build Coastguard Worker #include "umutex.h"
25*0e209d39SAndroid Build Coastguard Worker #include <float.h>
26*0e209d39SAndroid Build Coastguard Worker #include "gregoimp.h" // Math
27*0e209d39SAndroid Build Coastguard Worker #include "astro.h" // CalendarAstronomer and CalendarCache
28*0e209d39SAndroid Build Coastguard Worker #include "unicode/simpletz.h"
29*0e209d39SAndroid Build Coastguard Worker #include "uhash.h"
30*0e209d39SAndroid Build Coastguard Worker #include "ucln_in.h"
31*0e209d39SAndroid Build Coastguard Worker #include "cstring.h"
32*0e209d39SAndroid Build Coastguard Worker
33*0e209d39SAndroid Build Coastguard Worker // Debugging
34*0e209d39SAndroid Build Coastguard Worker #ifdef U_DEBUG_CHNSECAL
35*0e209d39SAndroid Build Coastguard Worker # include <stdio.h>
36*0e209d39SAndroid Build Coastguard Worker # include <stdarg.h>
debug_chnsecal_loc(const char * f,int32_t l)37*0e209d39SAndroid Build Coastguard Worker static void debug_chnsecal_loc(const char *f, int32_t l)
38*0e209d39SAndroid Build Coastguard Worker {
39*0e209d39SAndroid Build Coastguard Worker fprintf(stderr, "%s:%d: ", f, l);
40*0e209d39SAndroid Build Coastguard Worker }
41*0e209d39SAndroid Build Coastguard Worker
debug_chnsecal_msg(const char * pat,...)42*0e209d39SAndroid Build Coastguard Worker static void debug_chnsecal_msg(const char *pat, ...)
43*0e209d39SAndroid Build Coastguard Worker {
44*0e209d39SAndroid Build Coastguard Worker va_list ap;
45*0e209d39SAndroid Build Coastguard Worker va_start(ap, pat);
46*0e209d39SAndroid Build Coastguard Worker vfprintf(stderr, pat, ap);
47*0e209d39SAndroid Build Coastguard Worker fflush(stderr);
48*0e209d39SAndroid Build Coastguard Worker }
49*0e209d39SAndroid Build Coastguard Worker // must use double parens, i.e.: U_DEBUG_CHNSECAL_MSG(("four is: %d",4));
50*0e209d39SAndroid Build Coastguard Worker #define U_DEBUG_CHNSECAL_MSG(x) {debug_chnsecal_loc(__FILE__,__LINE__);debug_chnsecal_msg x;}
51*0e209d39SAndroid Build Coastguard Worker #else
52*0e209d39SAndroid Build Coastguard Worker #define U_DEBUG_CHNSECAL_MSG(x)
53*0e209d39SAndroid Build Coastguard Worker #endif
54*0e209d39SAndroid Build Coastguard Worker
55*0e209d39SAndroid Build Coastguard Worker
56*0e209d39SAndroid Build Coastguard Worker // Lazy Creation & Access synchronized by class CalendarCache with a mutex.
57*0e209d39SAndroid Build Coastguard Worker static icu::CalendarCache *gWinterSolsticeCache = nullptr;
58*0e209d39SAndroid Build Coastguard Worker static icu::CalendarCache *gNewYearCache = nullptr;
59*0e209d39SAndroid Build Coastguard Worker
60*0e209d39SAndroid Build Coastguard Worker static icu::TimeZone *gAstronomerTimeZone = nullptr;
61*0e209d39SAndroid Build Coastguard Worker static icu::UInitOnce gAstronomerTimeZoneInitOnce {};
62*0e209d39SAndroid Build Coastguard Worker
63*0e209d39SAndroid Build Coastguard Worker /**
64*0e209d39SAndroid Build Coastguard Worker * The start year of the Chinese calendar, the 61st year of the reign
65*0e209d39SAndroid Build Coastguard Worker * of Huang Di. Some sources use the first year of his reign,
66*0e209d39SAndroid Build Coastguard Worker * resulting in EXTENDED_YEAR values 60 years greater and ERA (cycle)
67*0e209d39SAndroid Build Coastguard Worker * values one greater.
68*0e209d39SAndroid Build Coastguard Worker */
69*0e209d39SAndroid Build Coastguard Worker static const int32_t CHINESE_EPOCH_YEAR = -2636; // Gregorian year
70*0e209d39SAndroid Build Coastguard Worker
71*0e209d39SAndroid Build Coastguard Worker /**
72*0e209d39SAndroid Build Coastguard Worker * The offset from GMT in milliseconds at which we perform astronomical
73*0e209d39SAndroid Build Coastguard Worker * computations. Some sources use a different historically accurate
74*0e209d39SAndroid Build Coastguard Worker * offset of GMT+7:45:40 for years before 1929; we do not do this.
75*0e209d39SAndroid Build Coastguard Worker */
76*0e209d39SAndroid Build Coastguard Worker static const int32_t CHINA_OFFSET = 8 * kOneHour;
77*0e209d39SAndroid Build Coastguard Worker
78*0e209d39SAndroid Build Coastguard Worker /**
79*0e209d39SAndroid Build Coastguard Worker * Value to be added or subtracted from the local days of a new moon to
80*0e209d39SAndroid Build Coastguard Worker * get close to the next or prior new moon, but not cross it. Must be
81*0e209d39SAndroid Build Coastguard Worker * >= 1 and < CalendarAstronomer.SYNODIC_MONTH.
82*0e209d39SAndroid Build Coastguard Worker */
83*0e209d39SAndroid Build Coastguard Worker static const int32_t SYNODIC_GAP = 25;
84*0e209d39SAndroid Build Coastguard Worker
85*0e209d39SAndroid Build Coastguard Worker
86*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
calendar_chinese_cleanup()87*0e209d39SAndroid Build Coastguard Worker static UBool calendar_chinese_cleanup() {
88*0e209d39SAndroid Build Coastguard Worker if (gWinterSolsticeCache) {
89*0e209d39SAndroid Build Coastguard Worker delete gWinterSolsticeCache;
90*0e209d39SAndroid Build Coastguard Worker gWinterSolsticeCache = nullptr;
91*0e209d39SAndroid Build Coastguard Worker }
92*0e209d39SAndroid Build Coastguard Worker if (gNewYearCache) {
93*0e209d39SAndroid Build Coastguard Worker delete gNewYearCache;
94*0e209d39SAndroid Build Coastguard Worker gNewYearCache = nullptr;
95*0e209d39SAndroid Build Coastguard Worker }
96*0e209d39SAndroid Build Coastguard Worker if (gAstronomerTimeZone) {
97*0e209d39SAndroid Build Coastguard Worker delete gAstronomerTimeZone;
98*0e209d39SAndroid Build Coastguard Worker gAstronomerTimeZone = nullptr;
99*0e209d39SAndroid Build Coastguard Worker }
100*0e209d39SAndroid Build Coastguard Worker gAstronomerTimeZoneInitOnce.reset();
101*0e209d39SAndroid Build Coastguard Worker return true;
102*0e209d39SAndroid Build Coastguard Worker }
103*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
104*0e209d39SAndroid Build Coastguard Worker
105*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
106*0e209d39SAndroid Build Coastguard Worker
107*0e209d39SAndroid Build Coastguard Worker
108*0e209d39SAndroid Build Coastguard Worker // Implementation of the ChineseCalendar class
109*0e209d39SAndroid Build Coastguard Worker
110*0e209d39SAndroid Build Coastguard Worker
111*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
112*0e209d39SAndroid Build Coastguard Worker // Constructors...
113*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
114*0e209d39SAndroid Build Coastguard Worker
115*0e209d39SAndroid Build Coastguard Worker
116*0e209d39SAndroid Build Coastguard Worker namespace {
117*0e209d39SAndroid Build Coastguard Worker
118*0e209d39SAndroid Build Coastguard Worker const TimeZone* getAstronomerTimeZone();
119*0e209d39SAndroid Build Coastguard Worker int32_t newMoonNear(const TimeZone*, double, UBool);
120*0e209d39SAndroid Build Coastguard Worker int32_t newYear(const icu::ChineseCalendar::Setting&, int32_t);
121*0e209d39SAndroid Build Coastguard Worker UBool isLeapMonthBetween(const TimeZone*, int32_t, int32_t);
122*0e209d39SAndroid Build Coastguard Worker
123*0e209d39SAndroid Build Coastguard Worker } // namespace
124*0e209d39SAndroid Build Coastguard Worker
clone() const125*0e209d39SAndroid Build Coastguard Worker ChineseCalendar* ChineseCalendar::clone() const {
126*0e209d39SAndroid Build Coastguard Worker return new ChineseCalendar(*this);
127*0e209d39SAndroid Build Coastguard Worker }
128*0e209d39SAndroid Build Coastguard Worker
ChineseCalendar(const Locale & aLocale,UErrorCode & success)129*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::ChineseCalendar(const Locale& aLocale, UErrorCode& success)
130*0e209d39SAndroid Build Coastguard Worker : Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success),
131*0e209d39SAndroid Build Coastguard Worker hasLeapMonthBetweenWinterSolstices(false)
132*0e209d39SAndroid Build Coastguard Worker {
133*0e209d39SAndroid Build Coastguard Worker setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
134*0e209d39SAndroid Build Coastguard Worker }
135*0e209d39SAndroid Build Coastguard Worker
ChineseCalendar(const ChineseCalendar & other)136*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::ChineseCalendar(const ChineseCalendar& other) : Calendar(other) {
137*0e209d39SAndroid Build Coastguard Worker hasLeapMonthBetweenWinterSolstices = other.hasLeapMonthBetweenWinterSolstices;
138*0e209d39SAndroid Build Coastguard Worker }
139*0e209d39SAndroid Build Coastguard Worker
~ChineseCalendar()140*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::~ChineseCalendar()
141*0e209d39SAndroid Build Coastguard Worker {
142*0e209d39SAndroid Build Coastguard Worker }
143*0e209d39SAndroid Build Coastguard Worker
getType() const144*0e209d39SAndroid Build Coastguard Worker const char *ChineseCalendar::getType() const {
145*0e209d39SAndroid Build Coastguard Worker return "chinese";
146*0e209d39SAndroid Build Coastguard Worker }
147*0e209d39SAndroid Build Coastguard Worker
148*0e209d39SAndroid Build Coastguard Worker namespace { // anonymous
149*0e209d39SAndroid Build Coastguard Worker
initAstronomerTimeZone()150*0e209d39SAndroid Build Coastguard Worker static void U_CALLCONV initAstronomerTimeZone() {
151*0e209d39SAndroid Build Coastguard Worker gAstronomerTimeZone = new SimpleTimeZone(CHINA_OFFSET, UNICODE_STRING_SIMPLE("CHINA_ZONE") );
152*0e209d39SAndroid Build Coastguard Worker ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
153*0e209d39SAndroid Build Coastguard Worker }
154*0e209d39SAndroid Build Coastguard Worker
getAstronomerTimeZone()155*0e209d39SAndroid Build Coastguard Worker const TimeZone* getAstronomerTimeZone() {
156*0e209d39SAndroid Build Coastguard Worker umtx_initOnce(gAstronomerTimeZoneInitOnce, &initAstronomerTimeZone);
157*0e209d39SAndroid Build Coastguard Worker return gAstronomerTimeZone;
158*0e209d39SAndroid Build Coastguard Worker }
159*0e209d39SAndroid Build Coastguard Worker
160*0e209d39SAndroid Build Coastguard Worker } // namespace anonymous
161*0e209d39SAndroid Build Coastguard Worker
162*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
163*0e209d39SAndroid Build Coastguard Worker // Minimum / Maximum access functions
164*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
165*0e209d39SAndroid Build Coastguard Worker
166*0e209d39SAndroid Build Coastguard Worker
167*0e209d39SAndroid Build Coastguard Worker static const int32_t LIMITS[UCAL_FIELD_COUNT][4] = {
168*0e209d39SAndroid Build Coastguard Worker // Minimum Greatest Least Maximum
169*0e209d39SAndroid Build Coastguard Worker // Minimum Maximum
170*0e209d39SAndroid Build Coastguard Worker { 1, 1, 83333, 83333}, // ERA
171*0e209d39SAndroid Build Coastguard Worker { 1, 1, 60, 60}, // YEAR
172*0e209d39SAndroid Build Coastguard Worker { 0, 0, 11, 11}, // MONTH
173*0e209d39SAndroid Build Coastguard Worker { 1, 1, 50, 55}, // WEEK_OF_YEAR
174*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
175*0e209d39SAndroid Build Coastguard Worker { 1, 1, 29, 30}, // DAY_OF_MONTH
176*0e209d39SAndroid Build Coastguard Worker { 1, 1, 353, 385}, // DAY_OF_YEAR
177*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
178*0e209d39SAndroid Build Coastguard Worker { -1, -1, 5, 5}, // DAY_OF_WEEK_IN_MONTH
179*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
180*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
181*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
182*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
183*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
184*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
185*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
186*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
187*0e209d39SAndroid Build Coastguard Worker { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
188*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
189*0e209d39SAndroid Build Coastguard Worker { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
190*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
191*0e209d39SAndroid Build Coastguard Worker {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
192*0e209d39SAndroid Build Coastguard Worker { 0, 0, 1, 1}, // IS_LEAP_MONTH
193*0e209d39SAndroid Build Coastguard Worker { 0, 0, 11, 12}, // ORDINAL_MONTH
194*0e209d39SAndroid Build Coastguard Worker };
195*0e209d39SAndroid Build Coastguard Worker
196*0e209d39SAndroid Build Coastguard Worker
197*0e209d39SAndroid Build Coastguard Worker /**
198*0e209d39SAndroid Build Coastguard Worker * @draft ICU 2.4
199*0e209d39SAndroid Build Coastguard Worker */
handleGetLimit(UCalendarDateFields field,ELimitType limitType) const200*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) const {
201*0e209d39SAndroid Build Coastguard Worker return LIMITS[field][limitType];
202*0e209d39SAndroid Build Coastguard Worker }
203*0e209d39SAndroid Build Coastguard Worker
204*0e209d39SAndroid Build Coastguard Worker
205*0e209d39SAndroid Build Coastguard Worker //----------------------------------------------------------------------
206*0e209d39SAndroid Build Coastguard Worker // Calendar framework
207*0e209d39SAndroid Build Coastguard Worker //----------------------------------------------------------------------
208*0e209d39SAndroid Build Coastguard Worker
209*0e209d39SAndroid Build Coastguard Worker /**
210*0e209d39SAndroid Build Coastguard Worker * Implement abstract Calendar method to return the extended year
211*0e209d39SAndroid Build Coastguard Worker * defined by the current fields. This will use either the ERA and
212*0e209d39SAndroid Build Coastguard Worker * YEAR field as the cycle and year-of-cycle, or the EXTENDED_YEAR
213*0e209d39SAndroid Build Coastguard Worker * field as the continuous year count, depending on which is newer.
214*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
215*0e209d39SAndroid Build Coastguard Worker */
handleGetExtendedYear(UErrorCode & status)216*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::handleGetExtendedYear(UErrorCode& status) {
217*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
218*0e209d39SAndroid Build Coastguard Worker return 0;
219*0e209d39SAndroid Build Coastguard Worker }
220*0e209d39SAndroid Build Coastguard Worker
221*0e209d39SAndroid Build Coastguard Worker int32_t year;
222*0e209d39SAndroid Build Coastguard Worker if (newestStamp(UCAL_ERA, UCAL_YEAR, kUnset) <= fStamp[UCAL_EXTENDED_YEAR]) {
223*0e209d39SAndroid Build Coastguard Worker year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
224*0e209d39SAndroid Build Coastguard Worker } else {
225*0e209d39SAndroid Build Coastguard Worker // adjust to the instance specific epoch
226*0e209d39SAndroid Build Coastguard Worker int32_t cycle = internalGet(UCAL_ERA, 1);
227*0e209d39SAndroid Build Coastguard Worker year = internalGet(UCAL_YEAR, 1);
228*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
229*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
230*0e209d39SAndroid Build Coastguard Worker return 0;
231*0e209d39SAndroid Build Coastguard Worker }
232*0e209d39SAndroid Build Coastguard Worker // Handle int32 overflow calculation for
233*0e209d39SAndroid Build Coastguard Worker // year = year + (cycle-1) * 60 -(fEpochYear - CHINESE_EPOCH_YEAR)
234*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(cycle, -1, &cycle) || // 0-based cycle
235*0e209d39SAndroid Build Coastguard Worker uprv_mul32_overflow(cycle, 60, &cycle) ||
236*0e209d39SAndroid Build Coastguard Worker uprv_add32_overflow(year, cycle, &year) ||
237*0e209d39SAndroid Build Coastguard Worker uprv_add32_overflow(year, -(setting.epochYear-CHINESE_EPOCH_YEAR),
238*0e209d39SAndroid Build Coastguard Worker &year)) {
239*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
240*0e209d39SAndroid Build Coastguard Worker return 0;
241*0e209d39SAndroid Build Coastguard Worker }
242*0e209d39SAndroid Build Coastguard Worker }
243*0e209d39SAndroid Build Coastguard Worker return year;
244*0e209d39SAndroid Build Coastguard Worker }
245*0e209d39SAndroid Build Coastguard Worker
246*0e209d39SAndroid Build Coastguard Worker /**
247*0e209d39SAndroid Build Coastguard Worker * Override Calendar method to return the number of days in the given
248*0e209d39SAndroid Build Coastguard Worker * extended year and month.
249*0e209d39SAndroid Build Coastguard Worker *
250*0e209d39SAndroid Build Coastguard Worker * <p>Note: This method also reads the IS_LEAP_MONTH field to determine
251*0e209d39SAndroid Build Coastguard Worker * whether or not the given month is a leap month.
252*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
253*0e209d39SAndroid Build Coastguard Worker */
handleGetMonthLength(int32_t extendedYear,int32_t month,UErrorCode & status) const254*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& status) const {
255*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
256*0e209d39SAndroid Build Coastguard Worker int32_t thisStart = handleComputeMonthStart(extendedYear, month, true, status);
257*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
258*0e209d39SAndroid Build Coastguard Worker return 0;
259*0e209d39SAndroid Build Coastguard Worker }
260*0e209d39SAndroid Build Coastguard Worker thisStart = thisStart -
261*0e209d39SAndroid Build Coastguard Worker kEpochStartAsJulianDay + 1; // Julian day -> local days
262*0e209d39SAndroid Build Coastguard Worker int32_t nextStart = newMoonNear(setting.zoneAstroCalc, thisStart + SYNODIC_GAP, true);
263*0e209d39SAndroid Build Coastguard Worker return nextStart - thisStart;
264*0e209d39SAndroid Build Coastguard Worker }
265*0e209d39SAndroid Build Coastguard Worker
266*0e209d39SAndroid Build Coastguard Worker /**
267*0e209d39SAndroid Build Coastguard Worker * Field resolution table that incorporates IS_LEAP_MONTH.
268*0e209d39SAndroid Build Coastguard Worker */
269*0e209d39SAndroid Build Coastguard Worker const UFieldResolutionTable ChineseCalendar::CHINESE_DATE_PRECEDENCE[] =
270*0e209d39SAndroid Build Coastguard Worker {
271*0e209d39SAndroid Build Coastguard Worker {
272*0e209d39SAndroid Build Coastguard Worker { UCAL_DAY_OF_MONTH, kResolveSTOP },
273*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_YEAR, UCAL_DAY_OF_WEEK, kResolveSTOP },
274*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
275*0e209d39SAndroid Build Coastguard Worker { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
276*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_YEAR, UCAL_DOW_LOCAL, kResolveSTOP },
277*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
278*0e209d39SAndroid Build Coastguard Worker { UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
279*0e209d39SAndroid Build Coastguard Worker { UCAL_DAY_OF_YEAR, kResolveSTOP },
280*0e209d39SAndroid Build Coastguard Worker { kResolveRemap | UCAL_DAY_OF_MONTH, UCAL_IS_LEAP_MONTH, kResolveSTOP },
281*0e209d39SAndroid Build Coastguard Worker { kResolveSTOP }
282*0e209d39SAndroid Build Coastguard Worker },
283*0e209d39SAndroid Build Coastguard Worker {
284*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_YEAR, kResolveSTOP },
285*0e209d39SAndroid Build Coastguard Worker { UCAL_WEEK_OF_MONTH, kResolveSTOP },
286*0e209d39SAndroid Build Coastguard Worker { UCAL_DAY_OF_WEEK_IN_MONTH, kResolveSTOP },
287*0e209d39SAndroid Build Coastguard Worker { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DAY_OF_WEEK, kResolveSTOP },
288*0e209d39SAndroid Build Coastguard Worker { kResolveRemap | UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_DOW_LOCAL, kResolveSTOP },
289*0e209d39SAndroid Build Coastguard Worker { kResolveSTOP }
290*0e209d39SAndroid Build Coastguard Worker },
291*0e209d39SAndroid Build Coastguard Worker {{kResolveSTOP}}
292*0e209d39SAndroid Build Coastguard Worker };
293*0e209d39SAndroid Build Coastguard Worker
294*0e209d39SAndroid Build Coastguard Worker /**
295*0e209d39SAndroid Build Coastguard Worker * Override Calendar to add IS_LEAP_MONTH to the field resolution
296*0e209d39SAndroid Build Coastguard Worker * table.
297*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
298*0e209d39SAndroid Build Coastguard Worker */
getFieldResolutionTable() const299*0e209d39SAndroid Build Coastguard Worker const UFieldResolutionTable* ChineseCalendar::getFieldResolutionTable() const {
300*0e209d39SAndroid Build Coastguard Worker return CHINESE_DATE_PRECEDENCE;
301*0e209d39SAndroid Build Coastguard Worker }
302*0e209d39SAndroid Build Coastguard Worker
303*0e209d39SAndroid Build Coastguard Worker namespace {
304*0e209d39SAndroid Build Coastguard Worker
305*0e209d39SAndroid Build Coastguard Worker struct MonthInfo {
306*0e209d39SAndroid Build Coastguard Worker int32_t month;
307*0e209d39SAndroid Build Coastguard Worker int32_t ordinalMonth;
308*0e209d39SAndroid Build Coastguard Worker int32_t thisMoon;
309*0e209d39SAndroid Build Coastguard Worker bool isLeapMonth;
310*0e209d39SAndroid Build Coastguard Worker bool hasLeapMonthBetweenWinterSolstices;
311*0e209d39SAndroid Build Coastguard Worker };
312*0e209d39SAndroid Build Coastguard Worker struct MonthInfo computeMonthInfo(
313*0e209d39SAndroid Build Coastguard Worker const icu::ChineseCalendar::Setting& setting,
314*0e209d39SAndroid Build Coastguard Worker int32_t gyear, int32_t days);
315*0e209d39SAndroid Build Coastguard Worker
316*0e209d39SAndroid Build Coastguard Worker } // namespace
317*0e209d39SAndroid Build Coastguard Worker
318*0e209d39SAndroid Build Coastguard Worker /**
319*0e209d39SAndroid Build Coastguard Worker * Return the Julian day number of day before the first day of the
320*0e209d39SAndroid Build Coastguard Worker * given month in the given extended year.
321*0e209d39SAndroid Build Coastguard Worker *
322*0e209d39SAndroid Build Coastguard Worker * <p>Note: This method reads the IS_LEAP_MONTH field to determine
323*0e209d39SAndroid Build Coastguard Worker * whether the given month is a leap month.
324*0e209d39SAndroid Build Coastguard Worker * @param eyear the extended year
325*0e209d39SAndroid Build Coastguard Worker * @param month the zero-based month. The month is also determined
326*0e209d39SAndroid Build Coastguard Worker * by reading the IS_LEAP_MONTH field.
327*0e209d39SAndroid Build Coastguard Worker * @return the Julian day number of the day before the first
328*0e209d39SAndroid Build Coastguard Worker * day of the given month and year
329*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
330*0e209d39SAndroid Build Coastguard Worker */
handleComputeMonthStart(int32_t eyear,int32_t month,UBool useMonth,UErrorCode & status) const331*0e209d39SAndroid Build Coastguard Worker int64_t ChineseCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth, UErrorCode& status) const {
332*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
333*0e209d39SAndroid Build Coastguard Worker return 0;
334*0e209d39SAndroid Build Coastguard Worker }
335*0e209d39SAndroid Build Coastguard Worker // If the month is out of range, adjust it into range, and
336*0e209d39SAndroid Build Coastguard Worker // modify the extended year value accordingly.
337*0e209d39SAndroid Build Coastguard Worker if (month < 0 || month > 11) {
338*0e209d39SAndroid Build Coastguard Worker double m = month;
339*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(eyear, ClockMath::floorDivide(m, 12.0, &m), &eyear)) {
340*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
341*0e209d39SAndroid Build Coastguard Worker return 0;
342*0e209d39SAndroid Build Coastguard Worker }
343*0e209d39SAndroid Build Coastguard Worker month = (int32_t)m;
344*0e209d39SAndroid Build Coastguard Worker }
345*0e209d39SAndroid Build Coastguard Worker
346*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
347*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
348*0e209d39SAndroid Build Coastguard Worker return 0;
349*0e209d39SAndroid Build Coastguard Worker }
350*0e209d39SAndroid Build Coastguard Worker int32_t gyear;
351*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(eyear, setting.epochYear - 1, &gyear)) {
352*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
353*0e209d39SAndroid Build Coastguard Worker return 0;
354*0e209d39SAndroid Build Coastguard Worker }
355*0e209d39SAndroid Build Coastguard Worker
356*0e209d39SAndroid Build Coastguard Worker int32_t theNewYear = newYear(setting, gyear);
357*0e209d39SAndroid Build Coastguard Worker int32_t newMoon = newMoonNear(setting.zoneAstroCalc, theNewYear + month * 29, true);
358*0e209d39SAndroid Build Coastguard Worker
359*0e209d39SAndroid Build Coastguard Worker // Ignore IS_LEAP_MONTH field if useMonth is false
360*0e209d39SAndroid Build Coastguard Worker bool isLeapMonth = false;
361*0e209d39SAndroid Build Coastguard Worker if (useMonth) {
362*0e209d39SAndroid Build Coastguard Worker isLeapMonth = internalGet(UCAL_IS_LEAP_MONTH) != 0;
363*0e209d39SAndroid Build Coastguard Worker }
364*0e209d39SAndroid Build Coastguard Worker
365*0e209d39SAndroid Build Coastguard Worker int32_t unusedMonth;
366*0e209d39SAndroid Build Coastguard Worker int32_t unusedDayOfWeek;
367*0e209d39SAndroid Build Coastguard Worker int32_t unusedDayOfMonth;
368*0e209d39SAndroid Build Coastguard Worker int32_t unusedDayOfYear;
369*0e209d39SAndroid Build Coastguard Worker Grego::dayToFields(newMoon, gyear, unusedMonth, unusedDayOfWeek, unusedDayOfMonth, unusedDayOfYear);
370*0e209d39SAndroid Build Coastguard Worker
371*0e209d39SAndroid Build Coastguard Worker struct MonthInfo monthInfo = computeMonthInfo(setting, gyear, newMoon);
372*0e209d39SAndroid Build Coastguard Worker if (month != monthInfo.month-1 || isLeapMonth != monthInfo.isLeapMonth) {
373*0e209d39SAndroid Build Coastguard Worker newMoon = newMoonNear(setting.zoneAstroCalc, newMoon + SYNODIC_GAP, true);
374*0e209d39SAndroid Build Coastguard Worker }
375*0e209d39SAndroid Build Coastguard Worker int32_t julianDay;
376*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(newMoon-1, kEpochStartAsJulianDay, &julianDay)) {
377*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
378*0e209d39SAndroid Build Coastguard Worker return 0;
379*0e209d39SAndroid Build Coastguard Worker }
380*0e209d39SAndroid Build Coastguard Worker
381*0e209d39SAndroid Build Coastguard Worker return julianDay;
382*0e209d39SAndroid Build Coastguard Worker }
383*0e209d39SAndroid Build Coastguard Worker
384*0e209d39SAndroid Build Coastguard Worker
385*0e209d39SAndroid Build Coastguard Worker /**
386*0e209d39SAndroid Build Coastguard Worker * Override Calendar to handle leap months properly.
387*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
388*0e209d39SAndroid Build Coastguard Worker */
add(UCalendarDateFields field,int32_t amount,UErrorCode & status)389*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::add(UCalendarDateFields field, int32_t amount, UErrorCode& status) {
390*0e209d39SAndroid Build Coastguard Worker switch (field) {
391*0e209d39SAndroid Build Coastguard Worker case UCAL_MONTH:
392*0e209d39SAndroid Build Coastguard Worker case UCAL_ORDINAL_MONTH:
393*0e209d39SAndroid Build Coastguard Worker if (amount != 0) {
394*0e209d39SAndroid Build Coastguard Worker int32_t dom = get(UCAL_DAY_OF_MONTH, status);
395*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) break;
396*0e209d39SAndroid Build Coastguard Worker int32_t day = get(UCAL_JULIAN_DAY, status) - kEpochStartAsJulianDay; // Get local day
397*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) break;
398*0e209d39SAndroid Build Coastguard Worker int32_t moon = day - dom + 1; // New moon
399*0e209d39SAndroid Build Coastguard Worker offsetMonth(moon, dom, amount, status);
400*0e209d39SAndroid Build Coastguard Worker }
401*0e209d39SAndroid Build Coastguard Worker break;
402*0e209d39SAndroid Build Coastguard Worker default:
403*0e209d39SAndroid Build Coastguard Worker Calendar::add(field, amount, status);
404*0e209d39SAndroid Build Coastguard Worker break;
405*0e209d39SAndroid Build Coastguard Worker }
406*0e209d39SAndroid Build Coastguard Worker }
407*0e209d39SAndroid Build Coastguard Worker
408*0e209d39SAndroid Build Coastguard Worker /**
409*0e209d39SAndroid Build Coastguard Worker * Override Calendar to handle leap months properly.
410*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
411*0e209d39SAndroid Build Coastguard Worker */
add(EDateFields field,int32_t amount,UErrorCode & status)412*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::add(EDateFields field, int32_t amount, UErrorCode& status) {
413*0e209d39SAndroid Build Coastguard Worker add((UCalendarDateFields)field, amount, status);
414*0e209d39SAndroid Build Coastguard Worker }
415*0e209d39SAndroid Build Coastguard Worker
416*0e209d39SAndroid Build Coastguard Worker namespace {
417*0e209d39SAndroid Build Coastguard Worker
418*0e209d39SAndroid Build Coastguard Worker struct RollMonthInfo {
419*0e209d39SAndroid Build Coastguard Worker int32_t month;
420*0e209d39SAndroid Build Coastguard Worker int32_t newMoon;
421*0e209d39SAndroid Build Coastguard Worker int32_t thisMoon;
422*0e209d39SAndroid Build Coastguard Worker };
423*0e209d39SAndroid Build Coastguard Worker
rollMonth(const TimeZone * timeZone,int32_t amount,int32_t day,int32_t month,int32_t dayOfMonth,bool isLeapMonth,bool hasLeapMonthBetweenWinterSolstices,UErrorCode & status)424*0e209d39SAndroid Build Coastguard Worker struct RollMonthInfo rollMonth(const TimeZone* timeZone, int32_t amount, int32_t day, int32_t month, int32_t dayOfMonth,
425*0e209d39SAndroid Build Coastguard Worker bool isLeapMonth, bool hasLeapMonthBetweenWinterSolstices,
426*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) {
427*0e209d39SAndroid Build Coastguard Worker struct RollMonthInfo output = {0, 0, 0};
428*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
429*0e209d39SAndroid Build Coastguard Worker return output;
430*0e209d39SAndroid Build Coastguard Worker }
431*0e209d39SAndroid Build Coastguard Worker
432*0e209d39SAndroid Build Coastguard Worker output.thisMoon = day - dayOfMonth + 1; // New moon (start of this month)
433*0e209d39SAndroid Build Coastguard Worker
434*0e209d39SAndroid Build Coastguard Worker // Note throughout the following: Months 12 and 1 are never
435*0e209d39SAndroid Build Coastguard Worker // followed by a leap month (D&R p. 185).
436*0e209d39SAndroid Build Coastguard Worker
437*0e209d39SAndroid Build Coastguard Worker // Compute the adjusted month number m. This is zero-based
438*0e209d39SAndroid Build Coastguard Worker // value from 0..11 in a non-leap year, and from 0..12 in a
439*0e209d39SAndroid Build Coastguard Worker // leap year.
440*0e209d39SAndroid Build Coastguard Worker if (hasLeapMonthBetweenWinterSolstices) { // (member variable)
441*0e209d39SAndroid Build Coastguard Worker if (isLeapMonth) {
442*0e209d39SAndroid Build Coastguard Worker ++month;
443*0e209d39SAndroid Build Coastguard Worker } else {
444*0e209d39SAndroid Build Coastguard Worker // Check for a prior leap month. (In the
445*0e209d39SAndroid Build Coastguard Worker // following, month 0 is the first month of the
446*0e209d39SAndroid Build Coastguard Worker // year.) Month 0 is never followed by a leap
447*0e209d39SAndroid Build Coastguard Worker // month, and we know month m is not a leap month.
448*0e209d39SAndroid Build Coastguard Worker // moon1 will be the start of month 0 if there is
449*0e209d39SAndroid Build Coastguard Worker // no leap month between month 0 and month m;
450*0e209d39SAndroid Build Coastguard Worker // otherwise it will be the start of month 1.
451*0e209d39SAndroid Build Coastguard Worker int prevMoon = output.thisMoon -
452*0e209d39SAndroid Build Coastguard Worker (int) (CalendarAstronomer::SYNODIC_MONTH * (month - 0.5));
453*0e209d39SAndroid Build Coastguard Worker prevMoon = newMoonNear(timeZone, prevMoon, true);
454*0e209d39SAndroid Build Coastguard Worker if (isLeapMonthBetween(timeZone, prevMoon, output.thisMoon)) {
455*0e209d39SAndroid Build Coastguard Worker ++month;
456*0e209d39SAndroid Build Coastguard Worker }
457*0e209d39SAndroid Build Coastguard Worker }
458*0e209d39SAndroid Build Coastguard Worker }
459*0e209d39SAndroid Build Coastguard Worker // Now do the standard roll computation on month, with the
460*0e209d39SAndroid Build Coastguard Worker // allowed range of 0..n-1, where n is 12 or 13.
461*0e209d39SAndroid Build Coastguard Worker int32_t numberOfMonths = hasLeapMonthBetweenWinterSolstices ? 13 : 12; // Months in this year
462*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(amount, month, &amount)) {
463*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
464*0e209d39SAndroid Build Coastguard Worker return output;
465*0e209d39SAndroid Build Coastguard Worker }
466*0e209d39SAndroid Build Coastguard Worker output.newMoon = amount % numberOfMonths;
467*0e209d39SAndroid Build Coastguard Worker if (output.newMoon < 0) {
468*0e209d39SAndroid Build Coastguard Worker output.newMoon += numberOfMonths;
469*0e209d39SAndroid Build Coastguard Worker }
470*0e209d39SAndroid Build Coastguard Worker output.month = month;
471*0e209d39SAndroid Build Coastguard Worker return output;
472*0e209d39SAndroid Build Coastguard Worker }
473*0e209d39SAndroid Build Coastguard Worker
474*0e209d39SAndroid Build Coastguard Worker } // namespace
475*0e209d39SAndroid Build Coastguard Worker
476*0e209d39SAndroid Build Coastguard Worker /**
477*0e209d39SAndroid Build Coastguard Worker * Override Calendar to handle leap months properly.
478*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
479*0e209d39SAndroid Build Coastguard Worker */
roll(UCalendarDateFields field,int32_t amount,UErrorCode & status)480*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) {
481*0e209d39SAndroid Build Coastguard Worker switch (field) {
482*0e209d39SAndroid Build Coastguard Worker case UCAL_MONTH:
483*0e209d39SAndroid Build Coastguard Worker case UCAL_ORDINAL_MONTH:
484*0e209d39SAndroid Build Coastguard Worker if (amount != 0) {
485*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
486*0e209d39SAndroid Build Coastguard Worker int32_t day = get(UCAL_JULIAN_DAY, status) - kEpochStartAsJulianDay; // Get local day
487*0e209d39SAndroid Build Coastguard Worker int32_t month = get(UCAL_MONTH, status); // 0-based month
488*0e209d39SAndroid Build Coastguard Worker int32_t dayOfMonth = get(UCAL_DAY_OF_MONTH, status);
489*0e209d39SAndroid Build Coastguard Worker bool isLeapMonth = get(UCAL_IS_LEAP_MONTH, status) == 1;
490*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) break;
491*0e209d39SAndroid Build Coastguard Worker struct RollMonthInfo r = rollMonth(setting.zoneAstroCalc, amount,
492*0e209d39SAndroid Build Coastguard Worker day, month, dayOfMonth, isLeapMonth, hasLeapMonthBetweenWinterSolstices, status);
493*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) break;
494*0e209d39SAndroid Build Coastguard Worker if (r.newMoon != r.month) {
495*0e209d39SAndroid Build Coastguard Worker offsetMonth(r.thisMoon, dayOfMonth, r.newMoon - r.month, status);
496*0e209d39SAndroid Build Coastguard Worker }
497*0e209d39SAndroid Build Coastguard Worker }
498*0e209d39SAndroid Build Coastguard Worker break;
499*0e209d39SAndroid Build Coastguard Worker default:
500*0e209d39SAndroid Build Coastguard Worker Calendar::roll(field, amount, status);
501*0e209d39SAndroid Build Coastguard Worker break;
502*0e209d39SAndroid Build Coastguard Worker }
503*0e209d39SAndroid Build Coastguard Worker }
504*0e209d39SAndroid Build Coastguard Worker
roll(EDateFields field,int32_t amount,UErrorCode & status)505*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::roll(EDateFields field, int32_t amount, UErrorCode& status) {
506*0e209d39SAndroid Build Coastguard Worker roll((UCalendarDateFields)field, amount, status);
507*0e209d39SAndroid Build Coastguard Worker }
508*0e209d39SAndroid Build Coastguard Worker
509*0e209d39SAndroid Build Coastguard Worker
510*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
511*0e209d39SAndroid Build Coastguard Worker // Support methods and constants
512*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
513*0e209d39SAndroid Build Coastguard Worker
514*0e209d39SAndroid Build Coastguard Worker namespace {
515*0e209d39SAndroid Build Coastguard Worker /**
516*0e209d39SAndroid Build Coastguard Worker * Convert local days to UTC epoch milliseconds.
517*0e209d39SAndroid Build Coastguard Worker * This is not an accurate conversion in that getTimezoneOffset
518*0e209d39SAndroid Build Coastguard Worker * takes the milliseconds in GMT (not local time). In theory, more
519*0e209d39SAndroid Build Coastguard Worker * accurate algorithm can be implemented but practically we do not need
520*0e209d39SAndroid Build Coastguard Worker * to go through that complication as long as the historical timezone
521*0e209d39SAndroid Build Coastguard Worker * changes did not happen around the 'tricky' new moon (new moon around
522*0e209d39SAndroid Build Coastguard Worker * midnight).
523*0e209d39SAndroid Build Coastguard Worker *
524*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
525*0e209d39SAndroid Build Coastguard Worker * @param days days after January 1, 1970 0:00 in the astronomical base zone
526*0e209d39SAndroid Build Coastguard Worker * @return milliseconds after January 1, 1970 0:00 GMT
527*0e209d39SAndroid Build Coastguard Worker */
daysToMillis(const TimeZone * timeZone,double days)528*0e209d39SAndroid Build Coastguard Worker double daysToMillis(const TimeZone* timeZone, double days) {
529*0e209d39SAndroid Build Coastguard Worker double millis = days * (double)kOneDay;
530*0e209d39SAndroid Build Coastguard Worker if (timeZone != nullptr) {
531*0e209d39SAndroid Build Coastguard Worker int32_t rawOffset, dstOffset;
532*0e209d39SAndroid Build Coastguard Worker UErrorCode status = U_ZERO_ERROR;
533*0e209d39SAndroid Build Coastguard Worker timeZone->getOffset(millis, false, rawOffset, dstOffset, status);
534*0e209d39SAndroid Build Coastguard Worker if (U_SUCCESS(status)) {
535*0e209d39SAndroid Build Coastguard Worker return millis - (double)(rawOffset + dstOffset);
536*0e209d39SAndroid Build Coastguard Worker }
537*0e209d39SAndroid Build Coastguard Worker }
538*0e209d39SAndroid Build Coastguard Worker return millis - (double)CHINA_OFFSET;
539*0e209d39SAndroid Build Coastguard Worker }
540*0e209d39SAndroid Build Coastguard Worker
541*0e209d39SAndroid Build Coastguard Worker /**
542*0e209d39SAndroid Build Coastguard Worker * Convert UTC epoch milliseconds to local days.
543*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
544*0e209d39SAndroid Build Coastguard Worker * @param millis milliseconds after January 1, 1970 0:00 GMT
545*0e209d39SAndroid Build Coastguard Worker * @return days after January 1, 1970 0:00 in the astronomical base zone
546*0e209d39SAndroid Build Coastguard Worker */
millisToDays(const TimeZone * timeZone,double millis)547*0e209d39SAndroid Build Coastguard Worker double millisToDays(const TimeZone* timeZone, double millis) {
548*0e209d39SAndroid Build Coastguard Worker if (timeZone != nullptr) {
549*0e209d39SAndroid Build Coastguard Worker int32_t rawOffset, dstOffset;
550*0e209d39SAndroid Build Coastguard Worker UErrorCode status = U_ZERO_ERROR;
551*0e209d39SAndroid Build Coastguard Worker timeZone->getOffset(millis, false, rawOffset, dstOffset, status);
552*0e209d39SAndroid Build Coastguard Worker if (U_SUCCESS(status)) {
553*0e209d39SAndroid Build Coastguard Worker return ClockMath::floorDivide(millis + (double)(rawOffset + dstOffset), kOneDay);
554*0e209d39SAndroid Build Coastguard Worker }
555*0e209d39SAndroid Build Coastguard Worker }
556*0e209d39SAndroid Build Coastguard Worker return ClockMath::floorDivide(millis + (double)CHINA_OFFSET, kOneDay);
557*0e209d39SAndroid Build Coastguard Worker }
558*0e209d39SAndroid Build Coastguard Worker
559*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
560*0e209d39SAndroid Build Coastguard Worker // Astronomical computations
561*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
562*0e209d39SAndroid Build Coastguard Worker
563*0e209d39SAndroid Build Coastguard Worker
564*0e209d39SAndroid Build Coastguard Worker /**
565*0e209d39SAndroid Build Coastguard Worker * Return the major solar term on or after December 15 of the given
566*0e209d39SAndroid Build Coastguard Worker * Gregorian year, that is, the winter solstice of the given year.
567*0e209d39SAndroid Build Coastguard Worker * Computations are relative to Asia/Shanghai time zone.
568*0e209d39SAndroid Build Coastguard Worker * @param setting setting (time zone and caches) for the Astro calculation.
569*0e209d39SAndroid Build Coastguard Worker * @param gyear a Gregorian year
570*0e209d39SAndroid Build Coastguard Worker * @return days after January 1, 1970 0:00 Asia/Shanghai of the
571*0e209d39SAndroid Build Coastguard Worker * winter solstice of the given year
572*0e209d39SAndroid Build Coastguard Worker */
winterSolstice(const icu::ChineseCalendar::Setting & setting,int32_t gyear)573*0e209d39SAndroid Build Coastguard Worker int32_t winterSolstice(const icu::ChineseCalendar::Setting& setting,
574*0e209d39SAndroid Build Coastguard Worker int32_t gyear) {
575*0e209d39SAndroid Build Coastguard Worker const TimeZone* timeZone = setting.zoneAstroCalc;
576*0e209d39SAndroid Build Coastguard Worker
577*0e209d39SAndroid Build Coastguard Worker UErrorCode status = U_ZERO_ERROR;
578*0e209d39SAndroid Build Coastguard Worker int32_t cacheValue = CalendarCache::get(setting.winterSolsticeCache, gyear, status);
579*0e209d39SAndroid Build Coastguard Worker
580*0e209d39SAndroid Build Coastguard Worker if (cacheValue == 0) {
581*0e209d39SAndroid Build Coastguard Worker // In books December 15 is used, but it fails for some years
582*0e209d39SAndroid Build Coastguard Worker // using our algorithms, e.g.: 1298 1391 1492 1553 1560. That
583*0e209d39SAndroid Build Coastguard Worker // is, winterSolstice(1298) starts search at Dec 14 08:00:00
584*0e209d39SAndroid Build Coastguard Worker // PST 1298 with a final result of Dec 14 10:31:59 PST 1299.
585*0e209d39SAndroid Build Coastguard Worker double ms = daysToMillis(timeZone, Grego::fieldsToDay(gyear, UCAL_DECEMBER, 1));
586*0e209d39SAndroid Build Coastguard Worker
587*0e209d39SAndroid Build Coastguard Worker // Winter solstice is 270 degrees solar longitude aka Dongzhi
588*0e209d39SAndroid Build Coastguard Worker double days = millisToDays(timeZone,
589*0e209d39SAndroid Build Coastguard Worker CalendarAstronomer(ms)
590*0e209d39SAndroid Build Coastguard Worker .getSunTime(CalendarAstronomer::WINTER_SOLSTICE(), true));
591*0e209d39SAndroid Build Coastguard Worker if (days < INT32_MIN || days > INT32_MAX) {
592*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
593*0e209d39SAndroid Build Coastguard Worker return 0;
594*0e209d39SAndroid Build Coastguard Worker }
595*0e209d39SAndroid Build Coastguard Worker cacheValue = (int32_t) days;
596*0e209d39SAndroid Build Coastguard Worker CalendarCache::put(setting.winterSolsticeCache, gyear, cacheValue, status);
597*0e209d39SAndroid Build Coastguard Worker }
598*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) {
599*0e209d39SAndroid Build Coastguard Worker cacheValue = 0;
600*0e209d39SAndroid Build Coastguard Worker }
601*0e209d39SAndroid Build Coastguard Worker return cacheValue;
602*0e209d39SAndroid Build Coastguard Worker }
603*0e209d39SAndroid Build Coastguard Worker
604*0e209d39SAndroid Build Coastguard Worker /**
605*0e209d39SAndroid Build Coastguard Worker * Return the closest new moon to the given date, searching either
606*0e209d39SAndroid Build Coastguard Worker * forward or backward in time.
607*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
608*0e209d39SAndroid Build Coastguard Worker * @param days days after January 1, 1970 0:00 Asia/Shanghai
609*0e209d39SAndroid Build Coastguard Worker * @param after if true, search for a new moon on or after the given
610*0e209d39SAndroid Build Coastguard Worker * date; otherwise, search for a new moon before it
611*0e209d39SAndroid Build Coastguard Worker * @return days after January 1, 1970 0:00 Asia/Shanghai of the nearest
612*0e209d39SAndroid Build Coastguard Worker * new moon after or before <code>days</code>
613*0e209d39SAndroid Build Coastguard Worker */
newMoonNear(const TimeZone * timeZone,double days,UBool after)614*0e209d39SAndroid Build Coastguard Worker int32_t newMoonNear(const TimeZone* timeZone, double days, UBool after) {
615*0e209d39SAndroid Build Coastguard Worker return (int32_t) millisToDays(
616*0e209d39SAndroid Build Coastguard Worker timeZone,
617*0e209d39SAndroid Build Coastguard Worker CalendarAstronomer(daysToMillis(timeZone, days))
618*0e209d39SAndroid Build Coastguard Worker .getMoonTime(CalendarAstronomer::NEW_MOON(), after));
619*0e209d39SAndroid Build Coastguard Worker }
620*0e209d39SAndroid Build Coastguard Worker
621*0e209d39SAndroid Build Coastguard Worker /**
622*0e209d39SAndroid Build Coastguard Worker * Return the nearest integer number of synodic months between
623*0e209d39SAndroid Build Coastguard Worker * two dates.
624*0e209d39SAndroid Build Coastguard Worker * @param day1 days after January 1, 1970 0:00 Asia/Shanghai
625*0e209d39SAndroid Build Coastguard Worker * @param day2 days after January 1, 1970 0:00 Asia/Shanghai
626*0e209d39SAndroid Build Coastguard Worker * @return the nearest integer number of months between day1 and day2
627*0e209d39SAndroid Build Coastguard Worker */
synodicMonthsBetween(int32_t day1,int32_t day2)628*0e209d39SAndroid Build Coastguard Worker int32_t synodicMonthsBetween(int32_t day1, int32_t day2) {
629*0e209d39SAndroid Build Coastguard Worker double roundme = ((day2 - day1) / CalendarAstronomer::SYNODIC_MONTH);
630*0e209d39SAndroid Build Coastguard Worker return (int32_t) (roundme + (roundme >= 0 ? .5 : -.5));
631*0e209d39SAndroid Build Coastguard Worker }
632*0e209d39SAndroid Build Coastguard Worker
633*0e209d39SAndroid Build Coastguard Worker /**
634*0e209d39SAndroid Build Coastguard Worker * Return the major solar term on or before a given date. This
635*0e209d39SAndroid Build Coastguard Worker * will be an integer from 1..12, with 1 corresponding to 330 degrees,
636*0e209d39SAndroid Build Coastguard Worker * 2 to 0 degrees, 3 to 30 degrees,..., and 12 to 300 degrees.
637*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
638*0e209d39SAndroid Build Coastguard Worker * @param days days after January 1, 1970 0:00 Asia/Shanghai
639*0e209d39SAndroid Build Coastguard Worker */
majorSolarTerm(const TimeZone * timeZone,int32_t days)640*0e209d39SAndroid Build Coastguard Worker int32_t majorSolarTerm(const TimeZone* timeZone, int32_t days) {
641*0e209d39SAndroid Build Coastguard Worker // Compute (floor(solarLongitude / (pi/6)) + 2) % 12
642*0e209d39SAndroid Build Coastguard Worker int32_t term = ( ((int32_t)(6 * CalendarAstronomer(daysToMillis(timeZone, days))
643*0e209d39SAndroid Build Coastguard Worker .getSunLongitude() / CalendarAstronomer::PI)) + 2 ) % 12;
644*0e209d39SAndroid Build Coastguard Worker if (term < 1) {
645*0e209d39SAndroid Build Coastguard Worker term += 12;
646*0e209d39SAndroid Build Coastguard Worker }
647*0e209d39SAndroid Build Coastguard Worker return term;
648*0e209d39SAndroid Build Coastguard Worker }
649*0e209d39SAndroid Build Coastguard Worker
650*0e209d39SAndroid Build Coastguard Worker /**
651*0e209d39SAndroid Build Coastguard Worker * Return true if the given month lacks a major solar term.
652*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
653*0e209d39SAndroid Build Coastguard Worker * @param newMoon days after January 1, 1970 0:00 Asia/Shanghai of a new
654*0e209d39SAndroid Build Coastguard Worker * moon
655*0e209d39SAndroid Build Coastguard Worker */
hasNoMajorSolarTerm(const TimeZone * timeZone,int32_t newMoon)656*0e209d39SAndroid Build Coastguard Worker UBool hasNoMajorSolarTerm(const TimeZone* timeZone, int32_t newMoon) {
657*0e209d39SAndroid Build Coastguard Worker return majorSolarTerm(timeZone, newMoon) ==
658*0e209d39SAndroid Build Coastguard Worker majorSolarTerm(timeZone, newMoonNear(timeZone, newMoon + SYNODIC_GAP, true));
659*0e209d39SAndroid Build Coastguard Worker }
660*0e209d39SAndroid Build Coastguard Worker
661*0e209d39SAndroid Build Coastguard Worker
662*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
663*0e209d39SAndroid Build Coastguard Worker // Time to fields
664*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
665*0e209d39SAndroid Build Coastguard Worker
666*0e209d39SAndroid Build Coastguard Worker /**
667*0e209d39SAndroid Build Coastguard Worker * Return true if there is a leap month on or after month newMoon1 and
668*0e209d39SAndroid Build Coastguard Worker * at or before month newMoon2.
669*0e209d39SAndroid Build Coastguard Worker * @param timeZone time zone for the Astro calculation.
670*0e209d39SAndroid Build Coastguard Worker * @param newMoon1 days after January 1, 1970 0:00 astronomical base zone
671*0e209d39SAndroid Build Coastguard Worker * of a new moon
672*0e209d39SAndroid Build Coastguard Worker * @param newMoon2 days after January 1, 1970 0:00 astronomical base zone
673*0e209d39SAndroid Build Coastguard Worker * of a new moon
674*0e209d39SAndroid Build Coastguard Worker */
isLeapMonthBetween(const TimeZone * timeZone,int32_t newMoon1,int32_t newMoon2)675*0e209d39SAndroid Build Coastguard Worker UBool isLeapMonthBetween(const TimeZone* timeZone, int32_t newMoon1, int32_t newMoon2) {
676*0e209d39SAndroid Build Coastguard Worker
677*0e209d39SAndroid Build Coastguard Worker #ifdef U_DEBUG_CHNSECAL
678*0e209d39SAndroid Build Coastguard Worker // This is only needed to debug the timeOfAngle divergence bug.
679*0e209d39SAndroid Build Coastguard Worker // Remove this later. Liu 11/9/00
680*0e209d39SAndroid Build Coastguard Worker if (synodicMonthsBetween(newMoon1, newMoon2) >= 50) {
681*0e209d39SAndroid Build Coastguard Worker U_DEBUG_CHNSECAL_MSG((
682*0e209d39SAndroid Build Coastguard Worker "isLeapMonthBetween(%d, %d): Invalid parameters", newMoon1, newMoon2
683*0e209d39SAndroid Build Coastguard Worker ));
684*0e209d39SAndroid Build Coastguard Worker }
685*0e209d39SAndroid Build Coastguard Worker #endif
686*0e209d39SAndroid Build Coastguard Worker
687*0e209d39SAndroid Build Coastguard Worker while (newMoon2 >= newMoon1) {
688*0e209d39SAndroid Build Coastguard Worker if (hasNoMajorSolarTerm(timeZone, newMoon2)) {
689*0e209d39SAndroid Build Coastguard Worker return true;
690*0e209d39SAndroid Build Coastguard Worker }
691*0e209d39SAndroid Build Coastguard Worker newMoon2 = newMoonNear(timeZone, newMoon2 - SYNODIC_GAP, false);
692*0e209d39SAndroid Build Coastguard Worker }
693*0e209d39SAndroid Build Coastguard Worker return false;
694*0e209d39SAndroid Build Coastguard Worker }
695*0e209d39SAndroid Build Coastguard Worker
696*0e209d39SAndroid Build Coastguard Worker
697*0e209d39SAndroid Build Coastguard Worker /**
698*0e209d39SAndroid Build Coastguard Worker * Compute the information about the year.
699*0e209d39SAndroid Build Coastguard Worker * @param setting setting (time zone and caches) for the Astro calculation.
700*0e209d39SAndroid Build Coastguard Worker * @param gyear the Gregorian year of the given date
701*0e209d39SAndroid Build Coastguard Worker * @param days days after January 1, 1970 0:00 astronomical base zone
702*0e209d39SAndroid Build Coastguard Worker * of the date to compute fields for
703*0e209d39SAndroid Build Coastguard Worker * @return The MonthInfo result.
704*0e209d39SAndroid Build Coastguard Worker */
computeMonthInfo(const icu::ChineseCalendar::Setting & setting,int32_t gyear,int32_t days)705*0e209d39SAndroid Build Coastguard Worker struct MonthInfo computeMonthInfo(
706*0e209d39SAndroid Build Coastguard Worker const icu::ChineseCalendar::Setting& setting,
707*0e209d39SAndroid Build Coastguard Worker int32_t gyear, int32_t days) {
708*0e209d39SAndroid Build Coastguard Worker struct MonthInfo output;
709*0e209d39SAndroid Build Coastguard Worker // Find the winter solstices before and after the target date.
710*0e209d39SAndroid Build Coastguard Worker // These define the boundaries of this Chinese year, specifically,
711*0e209d39SAndroid Build Coastguard Worker // the position of month 11, which always contains the solstice.
712*0e209d39SAndroid Build Coastguard Worker // We want solsticeBefore <= date < solsticeAfter.
713*0e209d39SAndroid Build Coastguard Worker int32_t solsticeBefore;
714*0e209d39SAndroid Build Coastguard Worker int32_t solsticeAfter = winterSolstice(setting, gyear);
715*0e209d39SAndroid Build Coastguard Worker if (days < solsticeAfter) {
716*0e209d39SAndroid Build Coastguard Worker solsticeBefore = winterSolstice(setting, gyear - 1);
717*0e209d39SAndroid Build Coastguard Worker } else {
718*0e209d39SAndroid Build Coastguard Worker solsticeBefore = solsticeAfter;
719*0e209d39SAndroid Build Coastguard Worker solsticeAfter = winterSolstice(setting, gyear + 1);
720*0e209d39SAndroid Build Coastguard Worker }
721*0e209d39SAndroid Build Coastguard Worker
722*0e209d39SAndroid Build Coastguard Worker const TimeZone* timeZone = setting.zoneAstroCalc;
723*0e209d39SAndroid Build Coastguard Worker // Find the start of the month after month 11. This will be either
724*0e209d39SAndroid Build Coastguard Worker // the prior month 12 or leap month 11 (very rare). Also find the
725*0e209d39SAndroid Build Coastguard Worker // start of the following month 11.
726*0e209d39SAndroid Build Coastguard Worker int32_t firstMoon = newMoonNear(timeZone, solsticeBefore + 1, true);
727*0e209d39SAndroid Build Coastguard Worker int32_t lastMoon = newMoonNear(timeZone, solsticeAfter + 1, false);
728*0e209d39SAndroid Build Coastguard Worker output.thisMoon = newMoonNear(timeZone, days + 1, false); // Start of this month
729*0e209d39SAndroid Build Coastguard Worker output.hasLeapMonthBetweenWinterSolstices = synodicMonthsBetween(firstMoon, lastMoon) == 12;
730*0e209d39SAndroid Build Coastguard Worker
731*0e209d39SAndroid Build Coastguard Worker output.month = synodicMonthsBetween(firstMoon, output.thisMoon);
732*0e209d39SAndroid Build Coastguard Worker int32_t theNewYear = newYear(setting, gyear);
733*0e209d39SAndroid Build Coastguard Worker if (days < theNewYear) {
734*0e209d39SAndroid Build Coastguard Worker theNewYear = newYear(setting, gyear-1);
735*0e209d39SAndroid Build Coastguard Worker }
736*0e209d39SAndroid Build Coastguard Worker if (output.hasLeapMonthBetweenWinterSolstices &&
737*0e209d39SAndroid Build Coastguard Worker isLeapMonthBetween(timeZone, firstMoon, output.thisMoon)) {
738*0e209d39SAndroid Build Coastguard Worker output.month--;
739*0e209d39SAndroid Build Coastguard Worker }
740*0e209d39SAndroid Build Coastguard Worker if (output.month < 1) {
741*0e209d39SAndroid Build Coastguard Worker output.month += 12;
742*0e209d39SAndroid Build Coastguard Worker }
743*0e209d39SAndroid Build Coastguard Worker output.ordinalMonth = synodicMonthsBetween(theNewYear, output.thisMoon);
744*0e209d39SAndroid Build Coastguard Worker if (output.ordinalMonth < 0) {
745*0e209d39SAndroid Build Coastguard Worker output.ordinalMonth += 12;
746*0e209d39SAndroid Build Coastguard Worker }
747*0e209d39SAndroid Build Coastguard Worker output.isLeapMonth = output.hasLeapMonthBetweenWinterSolstices &&
748*0e209d39SAndroid Build Coastguard Worker hasNoMajorSolarTerm(timeZone, output.thisMoon) &&
749*0e209d39SAndroid Build Coastguard Worker !isLeapMonthBetween(timeZone, firstMoon,
750*0e209d39SAndroid Build Coastguard Worker newMoonNear(timeZone, output.thisMoon - SYNODIC_GAP, false));
751*0e209d39SAndroid Build Coastguard Worker return output;
752*0e209d39SAndroid Build Coastguard Worker }
753*0e209d39SAndroid Build Coastguard Worker
754*0e209d39SAndroid Build Coastguard Worker } // namespace
755*0e209d39SAndroid Build Coastguard Worker
756*0e209d39SAndroid Build Coastguard Worker /**
757*0e209d39SAndroid Build Coastguard Worker * Override Calendar to compute several fields specific to the Chinese
758*0e209d39SAndroid Build Coastguard Worker * calendar system. These are:
759*0e209d39SAndroid Build Coastguard Worker *
760*0e209d39SAndroid Build Coastguard Worker * <ul><li>ERA
761*0e209d39SAndroid Build Coastguard Worker * <li>YEAR
762*0e209d39SAndroid Build Coastguard Worker * <li>MONTH
763*0e209d39SAndroid Build Coastguard Worker * <li>DAY_OF_MONTH
764*0e209d39SAndroid Build Coastguard Worker * <li>DAY_OF_YEAR
765*0e209d39SAndroid Build Coastguard Worker * <li>EXTENDED_YEAR</ul>
766*0e209d39SAndroid Build Coastguard Worker *
767*0e209d39SAndroid Build Coastguard Worker * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
768*0e209d39SAndroid Build Coastguard Worker * method is called. The getGregorianXxx() methods return Gregorian
769*0e209d39SAndroid Build Coastguard Worker * calendar equivalents for the given Julian day.
770*0e209d39SAndroid Build Coastguard Worker *
771*0e209d39SAndroid Build Coastguard Worker * <p>Compute the ChineseCalendar-specific field IS_LEAP_MONTH.
772*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
773*0e209d39SAndroid Build Coastguard Worker */
handleComputeFields(int32_t julianDay,UErrorCode & status)774*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::handleComputeFields(int32_t julianDay, UErrorCode & status) {
775*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
776*0e209d39SAndroid Build Coastguard Worker return;
777*0e209d39SAndroid Build Coastguard Worker }
778*0e209d39SAndroid Build Coastguard Worker int32_t days;
779*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(julianDay, -kEpochStartAsJulianDay, &days)) {
780*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
781*0e209d39SAndroid Build Coastguard Worker return;
782*0e209d39SAndroid Build Coastguard Worker }
783*0e209d39SAndroid Build Coastguard Worker int32_t gyear = getGregorianYear();
784*0e209d39SAndroid Build Coastguard Worker int32_t gmonth = getGregorianMonth();
785*0e209d39SAndroid Build Coastguard Worker
786*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
787*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
788*0e209d39SAndroid Build Coastguard Worker return;
789*0e209d39SAndroid Build Coastguard Worker }
790*0e209d39SAndroid Build Coastguard Worker struct MonthInfo monthInfo = computeMonthInfo(setting, gyear, days);
791*0e209d39SAndroid Build Coastguard Worker hasLeapMonthBetweenWinterSolstices = monthInfo.hasLeapMonthBetweenWinterSolstices;
792*0e209d39SAndroid Build Coastguard Worker
793*0e209d39SAndroid Build Coastguard Worker // Extended year and cycle year is based on the epoch year
794*0e209d39SAndroid Build Coastguard Worker int32_t eyear = gyear - setting.epochYear;
795*0e209d39SAndroid Build Coastguard Worker int32_t cycle_year = gyear - CHINESE_EPOCH_YEAR;
796*0e209d39SAndroid Build Coastguard Worker if (monthInfo.month < 11 ||
797*0e209d39SAndroid Build Coastguard Worker gmonth >= UCAL_JULY) {
798*0e209d39SAndroid Build Coastguard Worker eyear++;
799*0e209d39SAndroid Build Coastguard Worker cycle_year++;
800*0e209d39SAndroid Build Coastguard Worker }
801*0e209d39SAndroid Build Coastguard Worker int32_t dayOfMonth = days - monthInfo.thisMoon + 1;
802*0e209d39SAndroid Build Coastguard Worker
803*0e209d39SAndroid Build Coastguard Worker // 0->0,60 1->1,1 60->1,60 61->2,1 etc.
804*0e209d39SAndroid Build Coastguard Worker int32_t yearOfCycle;
805*0e209d39SAndroid Build Coastguard Worker int32_t cycle = ClockMath::floorDivide(cycle_year - 1, 60, &yearOfCycle);
806*0e209d39SAndroid Build Coastguard Worker
807*0e209d39SAndroid Build Coastguard Worker // Days will be before the first new year we compute if this
808*0e209d39SAndroid Build Coastguard Worker // date is in month 11, leap 11, 12. There is never a leap 12.
809*0e209d39SAndroid Build Coastguard Worker // New year computations are cached so this should be cheap in
810*0e209d39SAndroid Build Coastguard Worker // the long run.
811*0e209d39SAndroid Build Coastguard Worker int32_t theNewYear = newYear(setting, gyear);
812*0e209d39SAndroid Build Coastguard Worker if (days < theNewYear) {
813*0e209d39SAndroid Build Coastguard Worker theNewYear = newYear(setting, gyear-1);
814*0e209d39SAndroid Build Coastguard Worker }
815*0e209d39SAndroid Build Coastguard Worker cycle++;
816*0e209d39SAndroid Build Coastguard Worker yearOfCycle++;
817*0e209d39SAndroid Build Coastguard Worker int32_t dayOfYear = days - theNewYear + 1;
818*0e209d39SAndroid Build Coastguard Worker
819*0e209d39SAndroid Build Coastguard Worker int32_t minYear = this->handleGetLimit(UCAL_EXTENDED_YEAR, UCAL_LIMIT_MINIMUM);
820*0e209d39SAndroid Build Coastguard Worker if (eyear < minYear) {
821*0e209d39SAndroid Build Coastguard Worker if (!isLenient()) {
822*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
823*0e209d39SAndroid Build Coastguard Worker return;
824*0e209d39SAndroid Build Coastguard Worker }
825*0e209d39SAndroid Build Coastguard Worker eyear = minYear;
826*0e209d39SAndroid Build Coastguard Worker }
827*0e209d39SAndroid Build Coastguard Worker int32_t maxYear = this->handleGetLimit(UCAL_EXTENDED_YEAR, UCAL_LIMIT_MAXIMUM);
828*0e209d39SAndroid Build Coastguard Worker if (maxYear < eyear) {
829*0e209d39SAndroid Build Coastguard Worker if (!isLenient()) {
830*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
831*0e209d39SAndroid Build Coastguard Worker return;
832*0e209d39SAndroid Build Coastguard Worker }
833*0e209d39SAndroid Build Coastguard Worker eyear = maxYear;
834*0e209d39SAndroid Build Coastguard Worker }
835*0e209d39SAndroid Build Coastguard Worker
836*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_MONTH, monthInfo.month-1); // Convert from 1-based to 0-based
837*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_ORDINAL_MONTH, monthInfo.ordinalMonth); // Convert from 1-based to 0-based
838*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_IS_LEAP_MONTH, monthInfo.isLeapMonth?1:0);
839*0e209d39SAndroid Build Coastguard Worker
840*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_EXTENDED_YEAR, eyear);
841*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_ERA, cycle);
842*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_YEAR, yearOfCycle);
843*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_DAY_OF_MONTH, dayOfMonth);
844*0e209d39SAndroid Build Coastguard Worker internalSet(UCAL_DAY_OF_YEAR, dayOfYear);
845*0e209d39SAndroid Build Coastguard Worker }
846*0e209d39SAndroid Build Coastguard Worker
847*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
848*0e209d39SAndroid Build Coastguard Worker // Fields to time
849*0e209d39SAndroid Build Coastguard Worker //------------------------------------------------------------------
850*0e209d39SAndroid Build Coastguard Worker
851*0e209d39SAndroid Build Coastguard Worker namespace {
852*0e209d39SAndroid Build Coastguard Worker
853*0e209d39SAndroid Build Coastguard Worker /**
854*0e209d39SAndroid Build Coastguard Worker * Return the Chinese new year of the given Gregorian year.
855*0e209d39SAndroid Build Coastguard Worker * @param setting setting (time zone and caches) for the Astro calculation.
856*0e209d39SAndroid Build Coastguard Worker * @param gyear a Gregorian year
857*0e209d39SAndroid Build Coastguard Worker * @return days after January 1, 1970 0:00 astronomical base zone of the
858*0e209d39SAndroid Build Coastguard Worker * Chinese new year of the given year (this will be a new moon)
859*0e209d39SAndroid Build Coastguard Worker */
newYear(const icu::ChineseCalendar::Setting & setting,int32_t gyear)860*0e209d39SAndroid Build Coastguard Worker int32_t newYear(const icu::ChineseCalendar::Setting& setting,
861*0e209d39SAndroid Build Coastguard Worker int32_t gyear) {
862*0e209d39SAndroid Build Coastguard Worker const TimeZone* timeZone = setting.zoneAstroCalc;
863*0e209d39SAndroid Build Coastguard Worker UErrorCode status = U_ZERO_ERROR;
864*0e209d39SAndroid Build Coastguard Worker int32_t cacheValue = CalendarCache::get(setting.newYearCache, gyear, status);
865*0e209d39SAndroid Build Coastguard Worker
866*0e209d39SAndroid Build Coastguard Worker if (cacheValue == 0) {
867*0e209d39SAndroid Build Coastguard Worker
868*0e209d39SAndroid Build Coastguard Worker int32_t solsticeBefore= winterSolstice(setting, gyear - 1);
869*0e209d39SAndroid Build Coastguard Worker int32_t solsticeAfter = winterSolstice(setting, gyear);
870*0e209d39SAndroid Build Coastguard Worker int32_t newMoon1 = newMoonNear(timeZone, solsticeBefore + 1, true);
871*0e209d39SAndroid Build Coastguard Worker int32_t newMoon2 = newMoonNear(timeZone, newMoon1 + SYNODIC_GAP, true);
872*0e209d39SAndroid Build Coastguard Worker int32_t newMoon11 = newMoonNear(timeZone, solsticeAfter + 1, false);
873*0e209d39SAndroid Build Coastguard Worker
874*0e209d39SAndroid Build Coastguard Worker if (synodicMonthsBetween(newMoon1, newMoon11) == 12 &&
875*0e209d39SAndroid Build Coastguard Worker (hasNoMajorSolarTerm(timeZone, newMoon1) ||
876*0e209d39SAndroid Build Coastguard Worker hasNoMajorSolarTerm(timeZone, newMoon2))) {
877*0e209d39SAndroid Build Coastguard Worker cacheValue = newMoonNear(timeZone, newMoon2 + SYNODIC_GAP, true);
878*0e209d39SAndroid Build Coastguard Worker } else {
879*0e209d39SAndroid Build Coastguard Worker cacheValue = newMoon2;
880*0e209d39SAndroid Build Coastguard Worker }
881*0e209d39SAndroid Build Coastguard Worker
882*0e209d39SAndroid Build Coastguard Worker CalendarCache::put(setting.newYearCache, gyear, cacheValue, status);
883*0e209d39SAndroid Build Coastguard Worker }
884*0e209d39SAndroid Build Coastguard Worker if(U_FAILURE(status)) {
885*0e209d39SAndroid Build Coastguard Worker cacheValue = 0;
886*0e209d39SAndroid Build Coastguard Worker }
887*0e209d39SAndroid Build Coastguard Worker return cacheValue;
888*0e209d39SAndroid Build Coastguard Worker }
889*0e209d39SAndroid Build Coastguard Worker
890*0e209d39SAndroid Build Coastguard Worker } // namespace
891*0e209d39SAndroid Build Coastguard Worker
892*0e209d39SAndroid Build Coastguard Worker /**
893*0e209d39SAndroid Build Coastguard Worker * Adjust this calendar to be delta months before or after a given
894*0e209d39SAndroid Build Coastguard Worker * start position, pinning the day of month if necessary. The start
895*0e209d39SAndroid Build Coastguard Worker * position is given as a local days number for the start of the month
896*0e209d39SAndroid Build Coastguard Worker * and a day-of-month. Used by add() and roll().
897*0e209d39SAndroid Build Coastguard Worker * @param newMoon the local days of the first day of the month of the
898*0e209d39SAndroid Build Coastguard Worker * start position (days after January 1, 1970 0:00 Asia/Shanghai)
899*0e209d39SAndroid Build Coastguard Worker * @param dayOfMonth the 1-based day-of-month of the start position
900*0e209d39SAndroid Build Coastguard Worker * @param delta the number of months to move forward or backward from
901*0e209d39SAndroid Build Coastguard Worker * the start position
902*0e209d39SAndroid Build Coastguard Worker * @param status The status.
903*0e209d39SAndroid Build Coastguard Worker */
offsetMonth(int32_t newMoon,int32_t dayOfMonth,int32_t delta,UErrorCode & status)904*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::offsetMonth(int32_t newMoon, int32_t dayOfMonth, int32_t delta,
905*0e209d39SAndroid Build Coastguard Worker UErrorCode& status) {
906*0e209d39SAndroid Build Coastguard Worker const Setting setting = getSetting(status);
907*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) { return; }
908*0e209d39SAndroid Build Coastguard Worker
909*0e209d39SAndroid Build Coastguard Worker // Move to the middle of the month before our target month.
910*0e209d39SAndroid Build Coastguard Worker double value = newMoon;
911*0e209d39SAndroid Build Coastguard Worker value += (CalendarAstronomer::SYNODIC_MONTH *
912*0e209d39SAndroid Build Coastguard Worker (static_cast<double>(delta) - 0.5));
913*0e209d39SAndroid Build Coastguard Worker if (value < INT32_MIN || value > INT32_MAX) {
914*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
915*0e209d39SAndroid Build Coastguard Worker return;
916*0e209d39SAndroid Build Coastguard Worker }
917*0e209d39SAndroid Build Coastguard Worker newMoon = static_cast<int32_t>(value);
918*0e209d39SAndroid Build Coastguard Worker
919*0e209d39SAndroid Build Coastguard Worker // Search forward to the target month's new moon
920*0e209d39SAndroid Build Coastguard Worker newMoon = newMoonNear(setting.zoneAstroCalc, newMoon, true);
921*0e209d39SAndroid Build Coastguard Worker
922*0e209d39SAndroid Build Coastguard Worker // Find the target dayOfMonth
923*0e209d39SAndroid Build Coastguard Worker int32_t jd = newMoon + kEpochStartAsJulianDay - 1 + dayOfMonth;
924*0e209d39SAndroid Build Coastguard Worker
925*0e209d39SAndroid Build Coastguard Worker // Pin the dayOfMonth. In this calendar all months are 29 or 30 days
926*0e209d39SAndroid Build Coastguard Worker // so pinning just means handling dayOfMonth 30.
927*0e209d39SAndroid Build Coastguard Worker if (dayOfMonth > 29) {
928*0e209d39SAndroid Build Coastguard Worker set(UCAL_JULIAN_DAY, jd-1);
929*0e209d39SAndroid Build Coastguard Worker // TODO Fix this. We really shouldn't ever have to
930*0e209d39SAndroid Build Coastguard Worker // explicitly call complete(). This is either a bug in
931*0e209d39SAndroid Build Coastguard Worker // this method, in ChineseCalendar, or in
932*0e209d39SAndroid Build Coastguard Worker // Calendar.getActualMaximum(). I suspect the last.
933*0e209d39SAndroid Build Coastguard Worker complete(status);
934*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return;
935*0e209d39SAndroid Build Coastguard Worker if (getActualMaximum(UCAL_DAY_OF_MONTH, status) >= dayOfMonth) {
936*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return;
937*0e209d39SAndroid Build Coastguard Worker set(UCAL_JULIAN_DAY, jd);
938*0e209d39SAndroid Build Coastguard Worker }
939*0e209d39SAndroid Build Coastguard Worker } else {
940*0e209d39SAndroid Build Coastguard Worker set(UCAL_JULIAN_DAY, jd);
941*0e209d39SAndroid Build Coastguard Worker }
942*0e209d39SAndroid Build Coastguard Worker }
943*0e209d39SAndroid Build Coastguard Worker
944*0e209d39SAndroid Build Coastguard Worker constexpr uint32_t kChineseRelatedYearDiff = -2637;
945*0e209d39SAndroid Build Coastguard Worker
getRelatedYear(UErrorCode & status) const946*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::getRelatedYear(UErrorCode &status) const
947*0e209d39SAndroid Build Coastguard Worker {
948*0e209d39SAndroid Build Coastguard Worker int32_t year = get(UCAL_EXTENDED_YEAR, status);
949*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
950*0e209d39SAndroid Build Coastguard Worker return 0;
951*0e209d39SAndroid Build Coastguard Worker }
952*0e209d39SAndroid Build Coastguard Worker if (uprv_add32_overflow(year, kChineseRelatedYearDiff, &year)) {
953*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
954*0e209d39SAndroid Build Coastguard Worker return 0;
955*0e209d39SAndroid Build Coastguard Worker }
956*0e209d39SAndroid Build Coastguard Worker return year;
957*0e209d39SAndroid Build Coastguard Worker }
958*0e209d39SAndroid Build Coastguard Worker
setRelatedYear(int32_t year)959*0e209d39SAndroid Build Coastguard Worker void ChineseCalendar::setRelatedYear(int32_t year)
960*0e209d39SAndroid Build Coastguard Worker {
961*0e209d39SAndroid Build Coastguard Worker // set extended year
962*0e209d39SAndroid Build Coastguard Worker set(UCAL_EXTENDED_YEAR, year - kChineseRelatedYearDiff);
963*0e209d39SAndroid Build Coastguard Worker }
964*0e209d39SAndroid Build Coastguard Worker
965*0e209d39SAndroid Build Coastguard Worker IMPL_SYSTEM_DEFAULT_CENTURY(ChineseCalendar, "@calendar=chinese")
966*0e209d39SAndroid Build Coastguard Worker
967*0e209d39SAndroid Build Coastguard Worker bool
inTemporalLeapYear(UErrorCode & status) const968*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::inTemporalLeapYear(UErrorCode &status) const
969*0e209d39SAndroid Build Coastguard Worker {
970*0e209d39SAndroid Build Coastguard Worker int32_t days = getActualMaximum(UCAL_DAY_OF_YEAR, status);
971*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return false;
972*0e209d39SAndroid Build Coastguard Worker return days > 360;
973*0e209d39SAndroid Build Coastguard Worker }
974*0e209d39SAndroid Build Coastguard Worker
975*0e209d39SAndroid Build Coastguard Worker UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ChineseCalendar)
976*0e209d39SAndroid Build Coastguard Worker
977*0e209d39SAndroid Build Coastguard Worker
978*0e209d39SAndroid Build Coastguard Worker static const char * const gTemporalLeapMonthCodes[] = {
979*0e209d39SAndroid Build Coastguard Worker "M01L", "M02L", "M03L", "M04L", "M05L", "M06L",
980*0e209d39SAndroid Build Coastguard Worker "M07L", "M08L", "M09L", "M10L", "M11L", "M12L", nullptr
981*0e209d39SAndroid Build Coastguard Worker };
982*0e209d39SAndroid Build Coastguard Worker
getTemporalMonthCode(UErrorCode & status) const983*0e209d39SAndroid Build Coastguard Worker const char* ChineseCalendar::getTemporalMonthCode(UErrorCode &status) const {
984*0e209d39SAndroid Build Coastguard Worker // We need to call get, not internalGet, to force the calculation
985*0e209d39SAndroid Build Coastguard Worker // from UCAL_ORDINAL_MONTH.
986*0e209d39SAndroid Build Coastguard Worker int32_t is_leap = get(UCAL_IS_LEAP_MONTH, status);
987*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return nullptr;
988*0e209d39SAndroid Build Coastguard Worker if (is_leap != 0) {
989*0e209d39SAndroid Build Coastguard Worker int32_t month = get(UCAL_MONTH, status);
990*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return nullptr;
991*0e209d39SAndroid Build Coastguard Worker return gTemporalLeapMonthCodes[month];
992*0e209d39SAndroid Build Coastguard Worker }
993*0e209d39SAndroid Build Coastguard Worker return Calendar::getTemporalMonthCode(status);
994*0e209d39SAndroid Build Coastguard Worker }
995*0e209d39SAndroid Build Coastguard Worker
996*0e209d39SAndroid Build Coastguard Worker void
setTemporalMonthCode(const char * code,UErrorCode & status)997*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::setTemporalMonthCode(const char* code, UErrorCode& status )
998*0e209d39SAndroid Build Coastguard Worker {
999*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) return;
1000*0e209d39SAndroid Build Coastguard Worker int32_t len = static_cast<int32_t>(uprv_strlen(code));
1001*0e209d39SAndroid Build Coastguard Worker if (len != 4 || code[0] != 'M' || code[3] != 'L') {
1002*0e209d39SAndroid Build Coastguard Worker set(UCAL_IS_LEAP_MONTH, 0);
1003*0e209d39SAndroid Build Coastguard Worker return Calendar::setTemporalMonthCode(code, status);
1004*0e209d39SAndroid Build Coastguard Worker }
1005*0e209d39SAndroid Build Coastguard Worker for (int m = 0; gTemporalLeapMonthCodes[m] != nullptr; m++) {
1006*0e209d39SAndroid Build Coastguard Worker if (uprv_strcmp(code, gTemporalLeapMonthCodes[m]) == 0) {
1007*0e209d39SAndroid Build Coastguard Worker set(UCAL_MONTH, m);
1008*0e209d39SAndroid Build Coastguard Worker set(UCAL_IS_LEAP_MONTH, 1);
1009*0e209d39SAndroid Build Coastguard Worker return;
1010*0e209d39SAndroid Build Coastguard Worker }
1011*0e209d39SAndroid Build Coastguard Worker }
1012*0e209d39SAndroid Build Coastguard Worker status = U_ILLEGAL_ARGUMENT_ERROR;
1013*0e209d39SAndroid Build Coastguard Worker }
1014*0e209d39SAndroid Build Coastguard Worker
internalGetMonth(UErrorCode & status) const1015*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::internalGetMonth(UErrorCode& status) const {
1016*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
1017*0e209d39SAndroid Build Coastguard Worker return 0;
1018*0e209d39SAndroid Build Coastguard Worker }
1019*0e209d39SAndroid Build Coastguard Worker if (resolveFields(kMonthPrecedence) == UCAL_MONTH) {
1020*0e209d39SAndroid Build Coastguard Worker return internalGet(UCAL_MONTH);
1021*0e209d39SAndroid Build Coastguard Worker }
1022*0e209d39SAndroid Build Coastguard Worker LocalPointer<Calendar> temp(this->clone());
1023*0e209d39SAndroid Build Coastguard Worker temp->set(UCAL_MONTH, 0);
1024*0e209d39SAndroid Build Coastguard Worker temp->set(UCAL_IS_LEAP_MONTH, 0);
1025*0e209d39SAndroid Build Coastguard Worker temp->set(UCAL_DATE, 1);
1026*0e209d39SAndroid Build Coastguard Worker // Calculate the UCAL_MONTH and UCAL_IS_LEAP_MONTH by adding number of
1027*0e209d39SAndroid Build Coastguard Worker // months.
1028*0e209d39SAndroid Build Coastguard Worker temp->roll(UCAL_MONTH, internalGet(UCAL_ORDINAL_MONTH), status);
1029*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
1030*0e209d39SAndroid Build Coastguard Worker return 0;
1031*0e209d39SAndroid Build Coastguard Worker }
1032*0e209d39SAndroid Build Coastguard Worker
1033*0e209d39SAndroid Build Coastguard Worker ChineseCalendar *nonConstThis = (ChineseCalendar*)this; // cast away const
1034*0e209d39SAndroid Build Coastguard Worker nonConstThis->internalSet(UCAL_IS_LEAP_MONTH, temp->get(UCAL_IS_LEAP_MONTH, status));
1035*0e209d39SAndroid Build Coastguard Worker int32_t month = temp->get(UCAL_MONTH, status);
1036*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
1037*0e209d39SAndroid Build Coastguard Worker return 0;
1038*0e209d39SAndroid Build Coastguard Worker }
1039*0e209d39SAndroid Build Coastguard Worker nonConstThis->internalSet(UCAL_MONTH, month);
1040*0e209d39SAndroid Build Coastguard Worker return month;
1041*0e209d39SAndroid Build Coastguard Worker }
1042*0e209d39SAndroid Build Coastguard Worker
internalGetMonth(int32_t defaultValue,UErrorCode & status) const1043*0e209d39SAndroid Build Coastguard Worker int32_t ChineseCalendar::internalGetMonth(int32_t defaultValue, UErrorCode& status) const {
1044*0e209d39SAndroid Build Coastguard Worker if (U_FAILURE(status)) {
1045*0e209d39SAndroid Build Coastguard Worker return 0;
1046*0e209d39SAndroid Build Coastguard Worker }
1047*0e209d39SAndroid Build Coastguard Worker if (resolveFields(kMonthPrecedence) == UCAL_MONTH) {
1048*0e209d39SAndroid Build Coastguard Worker return internalGet(UCAL_MONTH, defaultValue);
1049*0e209d39SAndroid Build Coastguard Worker }
1050*0e209d39SAndroid Build Coastguard Worker return internalGetMonth(status);
1051*0e209d39SAndroid Build Coastguard Worker }
1052*0e209d39SAndroid Build Coastguard Worker
getSetting(UErrorCode &) const1053*0e209d39SAndroid Build Coastguard Worker ChineseCalendar::Setting ChineseCalendar::getSetting(UErrorCode&) const {
1054*0e209d39SAndroid Build Coastguard Worker return {
1055*0e209d39SAndroid Build Coastguard Worker CHINESE_EPOCH_YEAR,
1056*0e209d39SAndroid Build Coastguard Worker getAstronomerTimeZone(),
1057*0e209d39SAndroid Build Coastguard Worker &gWinterSolsticeCache,
1058*0e209d39SAndroid Build Coastguard Worker &gNewYearCache
1059*0e209d39SAndroid Build Coastguard Worker };
1060*0e209d39SAndroid Build Coastguard Worker }
1061*0e209d39SAndroid Build Coastguard Worker
1062*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
1063*0e209d39SAndroid Build Coastguard Worker
1064*0e209d39SAndroid Build Coastguard Worker #endif
1065*0e209d39SAndroid Build Coastguard Worker
1066