2 *******************************************************************************
3 * Copyright (C) 2003 - 2009, 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
);
137 const UDate
EthiopicCalendar::fgSystemDefaultCentury
= DBL_MIN
;
138 const int32_t EthiopicCalendar::fgSystemDefaultCenturyYear
= -1;
140 UDate
EthiopicCalendar::fgSystemDefaultCenturyStart
= DBL_MIN
;
141 int32_t EthiopicCalendar::fgSystemDefaultCenturyStartYear
= -1;
144 EthiopicCalendar::defaultCenturyStart() const
146 initializeSystemDefaultCentury();
147 return fgSystemDefaultCenturyStart
;
151 EthiopicCalendar::defaultCenturyStartYear() const
153 initializeSystemDefaultCentury();
154 if (isAmeteAlemEra()) {
155 return fgSystemDefaultCenturyStartYear
+ AMETE_MIHRET_DELTA
;
157 return fgSystemDefaultCenturyStartYear
;
161 EthiopicCalendar::initializeSystemDefaultCentury()
163 // lazy-evaluate systemDefaultCenturyStart
165 UMTX_CHECK(NULL
, (fgSystemDefaultCenturyStart
== fgSystemDefaultCentury
), needsUpdate
);
171 UErrorCode status
= U_ZERO_ERROR
;
173 EthiopicCalendar
calendar(Locale("@calendar=ethiopic"), status
);
174 if (U_SUCCESS(status
)) {
175 calendar
.setTime(Calendar::getNow(), status
);
176 calendar
.add(UCAL_YEAR
, -80, status
);
177 UDate newStart
= calendar
.getTime(status
);
178 int32_t newYear
= calendar
.get(UCAL_YEAR
, status
);
181 fgSystemDefaultCenturyStartYear
= newYear
;
182 fgSystemDefaultCenturyStart
= newStart
;
186 // We have no recourse upon failure unless we want to propagate the failure
191 EthiopicCalendar::getJDEpochOffset() const
193 return JD_EPOCH_OFFSET_AMETE_MIHRET
;
198 // We do not want to introduce this API in ICU4C.
199 // It was accidentally introduced in ICU4J as a public API.
201 //-------------------------------------------------------------------------
202 // Calendar system Conversion methods...
203 //-------------------------------------------------------------------------
206 EthiopicCalendar::ethiopicToJD(int32_t year
, int32_t month
, int32_t date
)
208 return ceToJD(year
, month
, date
, JD_EPOCH_OFFSET_AMETE_MIHRET
);