2 *******************************************************************************
3 * Copyright (C) 2003 - 2013, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
19 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicCalendar
)
21 //static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
22 static const int32_t JD_EPOCH_OFFSET_AMETE_MIHRET
= 1723856;
23 static const int32_t AMETE_MIHRET_DELTA
= 5500; // 5501 - 1 (Amete Alem 5501 = Amete Mihret 1)
25 //-------------------------------------------------------------------------
27 //-------------------------------------------------------------------------
29 EthiopicCalendar::EthiopicCalendar(const Locale
& aLocale
,
31 EEraType type
/*= AMETE_MIHRET_ERA*/)
32 : CECalendar(aLocale
, success
),
37 EthiopicCalendar::EthiopicCalendar(const EthiopicCalendar
& other
)
39 eraType(other
.eraType
)
43 EthiopicCalendar::~EthiopicCalendar()
48 EthiopicCalendar::clone() const
50 return new EthiopicCalendar(*this);
54 EthiopicCalendar::getType() const
56 if (isAmeteAlemEra()) {
57 return "ethiopic-amete-alem";
63 EthiopicCalendar::setAmeteAlemEra(UBool onOff
)
65 eraType
= onOff
? AMETE_ALEM_ERA
: AMETE_MIHRET_ERA
;
69 EthiopicCalendar::isAmeteAlemEra() const
71 return (eraType
== AMETE_ALEM_ERA
);
74 //-------------------------------------------------------------------------
76 //-------------------------------------------------------------------------
79 EthiopicCalendar::handleGetExtendedYear()
81 // Ethiopic calendar uses EXTENDED_YEAR aligned to
82 // Amelete Hihret year always.
84 if (newerField(UCAL_EXTENDED_YEAR
, UCAL_YEAR
) == UCAL_EXTENDED_YEAR
) {
85 eyear
= internalGet(UCAL_EXTENDED_YEAR
, 1); // Default to year 1
86 } else if (isAmeteAlemEra()) {
87 eyear
= internalGet(UCAL_YEAR
, 1 + AMETE_MIHRET_DELTA
)
88 - AMETE_MIHRET_DELTA
; // Default to year 1 of Amelete Mihret
90 // The year defaults to the epoch start, the era to AMETE_MIHRET
91 int32_t era
= internalGet(UCAL_ERA
, AMETE_MIHRET
);
92 if (era
== AMETE_MIHRET
) {
93 eyear
= internalGet(UCAL_YEAR
, 1); // Default to year 1
95 eyear
= internalGet(UCAL_YEAR
, 1) - AMETE_MIHRET_DELTA
;
102 EthiopicCalendar::handleComputeFields(int32_t julianDay
, UErrorCode
&/*status*/)
104 int32_t eyear
, month
, day
, era
, year
;
105 jdToCE(julianDay
, getJDEpochOffset(), eyear
, month
, day
);
107 if (isAmeteAlemEra()) {
109 year
= eyear
+ AMETE_MIHRET_DELTA
;
116 year
= eyear
+ AMETE_MIHRET_DELTA
;
120 internalSet(UCAL_EXTENDED_YEAR
, eyear
);
121 internalSet(UCAL_ERA
, era
);
122 internalSet(UCAL_YEAR
, year
);
123 internalSet(UCAL_MONTH
, month
);
124 internalSet(UCAL_DATE
, day
);
125 internalSet(UCAL_DAY_OF_YEAR
, (30 * month
) + day
);
129 EthiopicCalendar::handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const
131 if (isAmeteAlemEra() && field
== UCAL_ERA
) {
132 return 0; // Only one era in this mode, era is always 0
134 return CECalendar::handleGetLimit(field
, limitType
);
138 * The system maintains a static default century start date and Year. They are
139 * initialized the first time they are used. Once the system default century date
140 * and year are set, they do not change.
142 static UDate gSystemDefaultCenturyStart
= DBL_MIN
;
143 static int32_t gSystemDefaultCenturyStartYear
= -1;
144 static icu::UInitOnce gSystemDefaultCenturyInit
= U_INITONCE_INITIALIZER
;
146 static void U_CALLCONV
initializeSystemDefaultCentury()
148 UErrorCode status
= U_ZERO_ERROR
;
149 EthiopicCalendar
calendar(Locale("@calendar=ethiopic"), status
);
150 if (U_SUCCESS(status
)) {
151 calendar
.setTime(Calendar::getNow(), status
);
152 calendar
.add(UCAL_YEAR
, -80, status
);
154 gSystemDefaultCenturyStart
= calendar
.getTime(status
);
155 gSystemDefaultCenturyStartYear
= calendar
.get(UCAL_YEAR
, status
);
157 // We have no recourse upon failure unless we want to propagate the failure
162 EthiopicCalendar::defaultCenturyStart() const
164 // lazy-evaluate systemDefaultCenturyStart
165 umtx_initOnce(gSystemDefaultCenturyInit
, &initializeSystemDefaultCentury
);
166 return gSystemDefaultCenturyStart
;
170 EthiopicCalendar::defaultCenturyStartYear() const
172 // lazy-evaluate systemDefaultCenturyStartYear
173 umtx_initOnce(gSystemDefaultCenturyInit
, &initializeSystemDefaultCentury
);
174 if (isAmeteAlemEra()) {
175 return gSystemDefaultCenturyStartYear
+ AMETE_MIHRET_DELTA
;
177 return gSystemDefaultCenturyStartYear
;
182 EthiopicCalendar::getJDEpochOffset() const
184 return JD_EPOCH_OFFSET_AMETE_MIHRET
;
189 // We do not want to introduce this API in ICU4C.
190 // It was accidentally introduced in ICU4J as a public API.
192 //-------------------------------------------------------------------------
193 // Calendar system Conversion methods...
194 //-------------------------------------------------------------------------
197 EthiopicCalendar::ethiopicToJD(int32_t year
, int32_t month
, int32_t date
)
199 return ceToJD(year
, month
, date
, JD_EPOCH_OFFSET_AMETE_MIHRET
);