1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2003 - 2009, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
15 #include "gregoimp.h" //Math
19 static const int32_t LIMITS
[UCAL_FIELD_COUNT
][4] = {
20 // Minimum Greatest Least Maximum
23 { 1, 1, 5000000, 5000000}, // YEAR
24 { 0, 0, 12, 12}, // MONTH
25 { 1, 1, 52, 53}, // WEEK_OF_YEAR
26 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // WEEK_OF_MONTH
27 { 1, 1, 5, 30}, // DAY_OF_MONTH
28 { 1, 1, 365, 366}, // DAY_OF_YEAR
29 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
30 { -1, -1, 1, 5}, // DAY_OF_WEEK_IN_MONTH
31 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // AM_PM
32 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
33 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
34 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
35 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
36 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
37 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
38 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
39 { -5000000, -5000000, 5000000, 5000000}, // YEAR_WOY
40 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
41 { -5000000, -5000000, 5000000, 5000000}, // EXTENDED_YEAR
42 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
43 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
44 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // IS_LEAP_MONTH
47 //-------------------------------------------------------------------------
49 //-------------------------------------------------------------------------
51 CECalendar::CECalendar(const Locale
& aLocale
, UErrorCode
& success
)
52 : Calendar(TimeZone::createDefault(), aLocale
, success
)
54 setTimeInMillis(getNow(), success
);
57 CECalendar::CECalendar (const CECalendar
& other
)
62 CECalendar::~CECalendar()
67 CECalendar::operator=(const CECalendar
& right
)
69 Calendar::operator=(right
);
73 //-------------------------------------------------------------------------
75 //-------------------------------------------------------------------------
78 CECalendar::handleComputeMonthStart(int32_t eyear
,int32_t emonth
, UBool
/*useMonth*/) const
80 return ceToJD(eyear
, emonth
, 0, getJDEpochOffset());
84 CECalendar::handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const
86 return LIMITS
[field
][limitType
];
90 CECalendar::inDaylightTime(UErrorCode
& status
) const
92 if (U_FAILURE(status
) || !getTimeZone().useDaylightTime()) {
96 // Force an update of the state of the Calendar.
97 ((CECalendar
*)this)->complete(status
); // cast away const
99 return (UBool
)(U_SUCCESS(status
) ? (internalGet(UCAL_DST_OFFSET
) != 0) : FALSE
);
103 CECalendar::haveDefaultCentury() const
108 //-------------------------------------------------------------------------
109 // Calendar system Conversion methods...
110 //-------------------------------------------------------------------------
112 CECalendar::ceToJD(int32_t year
, int32_t month
, int32_t date
, int32_t jdEpochOffset
)
114 // handle month > 12, < 0 (e.g. from add/set)
120 year
+= month
/13 - 1;
121 month
= month%13
+ 12;
124 jdEpochOffset
// difference from Julian epoch to 1,1,1
125 + 365 * year
// number of days from years
126 + ClockMath::floorDivide(year
, 4) // extra day of leap year
127 + 30 * month
// number of days from months (months are 0-based)
128 + date
- 1 // number of days for present month (1 based)
133 CECalendar::jdToCE(int32_t julianDay
, int32_t jdEpochOffset
, int32_t& year
, int32_t& month
, int32_t& day
)
135 int32_t c4
; // number of 4 year cycle (1461 days)
136 int32_t r4
; // remainder of 4 year cycle, always positive
138 c4
= ClockMath::floorDivide(julianDay
- jdEpochOffset
, 1461, r4
);
140 year
= 4 * c4
+ (r4
/365 - r4
/1460); // 4 * <number of 4year cycle> + <years within the last cycle>
142 int32_t doy
= (r4
== 1460) ? 365 : (r4
% 365); // days in present year
144 month
= doy
/ 30; // 30 -> Coptic/Ethiopic month length up to 12th month
145 day
= (doy
% 30) + 1; // 1-based days in a month
150 #endif /* #if !UCONFIG_NO_FORMATTING */