1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2003 - 2013, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 *******************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
21 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicCalendar
)
23 //static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
24 static const int32_t JD_EPOCH_OFFSET_AMETE_MIHRET
= 1723856;
25 static const int32_t AMETE_MIHRET_DELTA
= 5500; // 5501 - 1 (Amete Alem 5501 = Amete Mihret 1)
27 //-------------------------------------------------------------------------
29 //-------------------------------------------------------------------------
31 EthiopicCalendar::EthiopicCalendar(const Locale
& aLocale
,
33 EEraType type
/*= AMETE_MIHRET_ERA*/)
34 : CECalendar(aLocale
, success
),
39 EthiopicCalendar::EthiopicCalendar(const EthiopicCalendar
& other
)
41 eraType(other
.eraType
)
45 EthiopicCalendar::~EthiopicCalendar()
50 EthiopicCalendar::clone() const
52 return new EthiopicCalendar(*this);
56 EthiopicCalendar::getType() const
58 if (isAmeteAlemEra()) {
59 return "ethiopic-amete-alem";
65 EthiopicCalendar::setAmeteAlemEra(UBool onOff
)
67 eraType
= onOff
? AMETE_ALEM_ERA
: AMETE_MIHRET_ERA
;
71 EthiopicCalendar::isAmeteAlemEra() const
73 return (eraType
== AMETE_ALEM_ERA
);
76 //-------------------------------------------------------------------------
78 //-------------------------------------------------------------------------
81 EthiopicCalendar::handleGetExtendedYear()
83 // Ethiopic calendar uses EXTENDED_YEAR aligned to
84 // Amelete Hihret year always.
86 if (newerField(UCAL_EXTENDED_YEAR
, UCAL_YEAR
) == UCAL_EXTENDED_YEAR
) {
87 eyear
= internalGet(UCAL_EXTENDED_YEAR
, 1); // Default to year 1
88 } else if (isAmeteAlemEra()) {
89 eyear
= internalGet(UCAL_YEAR
, 1 + AMETE_MIHRET_DELTA
)
90 - AMETE_MIHRET_DELTA
; // Default to year 1 of Amelete Mihret
92 // The year defaults to the epoch start, the era to AMETE_MIHRET
93 int32_t era
= internalGet(UCAL_ERA
, AMETE_MIHRET
);
94 if (era
== AMETE_MIHRET
) {
95 eyear
= internalGet(UCAL_YEAR
, 1); // Default to year 1
97 eyear
= internalGet(UCAL_YEAR
, 1) - AMETE_MIHRET_DELTA
;
104 EthiopicCalendar::handleComputeFields(int32_t julianDay
, UErrorCode
&/*status*/)
106 int32_t eyear
, month
, day
, era
, year
;
107 jdToCE(julianDay
, getJDEpochOffset(), eyear
, month
, day
);
109 if (isAmeteAlemEra()) {
111 year
= eyear
+ AMETE_MIHRET_DELTA
;
118 year
= eyear
+ AMETE_MIHRET_DELTA
;
122 internalSet(UCAL_EXTENDED_YEAR
, eyear
);
123 internalSet(UCAL_ERA
, era
);
124 internalSet(UCAL_YEAR
, year
);
125 internalSet(UCAL_MONTH
, month
);
126 internalSet(UCAL_DATE
, day
);
127 internalSet(UCAL_DAY_OF_YEAR
, (30 * month
) + day
);
131 EthiopicCalendar::handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const
133 if (isAmeteAlemEra() && field
== UCAL_ERA
) {
134 return 0; // Only one era in this mode, era is always 0
136 return CECalendar::handleGetLimit(field
, limitType
);
140 * The system maintains a static default century start date and Year. They are
141 * initialized the first time they are used. Once the system default century date
142 * and year are set, they do not change.
144 static UDate gSystemDefaultCenturyStart
= DBL_MIN
;
145 static int32_t gSystemDefaultCenturyStartYear
= -1;
146 static icu::UInitOnce gSystemDefaultCenturyInit
= U_INITONCE_INITIALIZER
;
148 static void U_CALLCONV
initializeSystemDefaultCentury()
150 UErrorCode status
= U_ZERO_ERROR
;
151 EthiopicCalendar
calendar(Locale("@calendar=ethiopic"), status
);
152 if (U_SUCCESS(status
)) {
153 calendar
.setTime(Calendar::getNow(), status
);
154 calendar
.add(UCAL_YEAR
, -80, status
);
156 gSystemDefaultCenturyStart
= calendar
.getTime(status
);
157 gSystemDefaultCenturyStartYear
= calendar
.get(UCAL_YEAR
, status
);
159 // We have no recourse upon failure unless we want to propagate the failure
164 EthiopicCalendar::defaultCenturyStart() const
166 // lazy-evaluate systemDefaultCenturyStart
167 umtx_initOnce(gSystemDefaultCenturyInit
, &initializeSystemDefaultCentury
);
168 return gSystemDefaultCenturyStart
;
172 EthiopicCalendar::defaultCenturyStartYear() const
174 // lazy-evaluate systemDefaultCenturyStartYear
175 umtx_initOnce(gSystemDefaultCenturyInit
, &initializeSystemDefaultCentury
);
176 if (isAmeteAlemEra()) {
177 return gSystemDefaultCenturyStartYear
+ AMETE_MIHRET_DELTA
;
179 return gSystemDefaultCenturyStartYear
;
184 EthiopicCalendar::getJDEpochOffset() const
186 return JD_EPOCH_OFFSET_AMETE_MIHRET
;
191 // We do not want to introduce this API in ICU4C.
192 // It was accidentally introduced in ICU4J as a public API.
194 //-------------------------------------------------------------------------
195 // Calendar system Conversion methods...
196 //-------------------------------------------------------------------------
199 EthiopicCalendar::ethiopicToJD(int32_t year
, int32_t month
, int32_t date
)
201 return ceToJD(year
, month
, date
, JD_EPOCH_OFFSET_AMETE_MIHRET
);