Skip to content

Commit f362ced

Browse files
committed
ICU-23167 Change Ethiopian Amete Alem epoch
See #3602
1 parent ae4a345 commit f362ced

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

icu4c/source/i18n/ethpccal.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ U_NAMESPACE_BEGIN
2222
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicCalendar)
2323
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EthiopicAmeteAlemCalendar)
2424

25-
//static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
25+
static const int32_t JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
2626
static const int32_t JD_EPOCH_OFFSET_AMETE_MIHRET = 1723856;
2727
static const int32_t AMETE_MIHRET_DELTA = 5500; // 5501 - 1 (Amete Alem 5501 = Amete Mihret 1)
2828

@@ -141,21 +141,22 @@ EthiopicAmeteAlemCalendar::handleGetExtendedYear(UErrorCode& status)
141141
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
142142
return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
143143
}
144-
// Default to year 1 of Amelete Mihret
145-
int32_t year = internalGet(UCAL_YEAR, 1 + AMETE_MIHRET_DELTA);
146-
if (uprv_add32_overflow(year, -AMETE_MIHRET_DELTA, &year)) {
147-
status = U_ILLEGAL_ARGUMENT_ERROR;
148-
return 0;
149-
}
150-
return year;
144+
// Default to year 1
145+
return internalGet(UCAL_YEAR, 1);
146+
}
147+
148+
int32_t
149+
EthiopicAmeteAlemCalendar::getJDEpochOffset() const
150+
{
151+
return JD_EPOCH_OFFSET_AMETE_ALEM;
151152
}
152153

153154
int32_t EthiopicAmeteAlemCalendar::extendedYearToEra(int32_t /* extendedYear */) const {
154155
return AMETE_ALEM;
155156
}
156157

157158
int32_t EthiopicAmeteAlemCalendar::extendedYearToYear(int32_t extendedYear) const {
158-
return extendedYear + AMETE_MIHRET_DELTA;
159+
return extendedYear;
159160
}
160161

161162

@@ -168,17 +169,6 @@ EthiopicAmeteAlemCalendar::handleGetLimit(UCalendarDateFields field, ELimitType
168169
return EthiopicCalendar::handleGetLimit(field, limitType);
169170
}
170171

171-
int32_t
172-
EthiopicAmeteAlemCalendar::defaultCenturyStartYear() const
173-
{
174-
return EthiopicCalendar::defaultCenturyStartYear() + AMETE_MIHRET_DELTA;
175-
}
176-
177-
178-
int32_t EthiopicAmeteAlemCalendar::getRelatedYearDifference() const {
179-
constexpr int32_t kEthiopicAmeteAlemCalendarRelatedYearDifference = -5492;
180-
return kEthiopicAmeteAlemCalendarRelatedYearDifference;
181-
}
182172
U_NAMESPACE_END
183173

184174
#endif

icu4c/source/i18n/ethpccal.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,6 @@ class EthiopicAmeteAlemCalendar : public EthiopicCalendar {
304304
// Calendar framework
305305
//-------------------------------------------------------------------------
306306

307-
/**
308-
* @internal
309-
*/
310-
int32_t getRelatedYearDifference() const override;
311-
312307
/**
313308
* Return the extended year defined by the current fields.
314309
* This calendar use only AMETE_ALEM for the era.
@@ -325,11 +320,12 @@ class EthiopicAmeteAlemCalendar : public EthiopicCalendar {
325320
* @internal
326321
*/
327322
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
323+
328324
/**
329-
* Returns the year in which the default century begins
325+
* Return the date offset from Julian
330326
* @internal
331327
*/
332-
virtual int32_t defaultCenturyStartYear() const override;
328+
int32_t getJDEpochOffset() const override;
333329

334330
/**
335331
* Compute the era from extended year.

icu4c/source/test/intltest/caltest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2994,7 +2994,7 @@ void CalendarTest::TestBasicConversionEthiopicAmeteAlem() {
29942994
AsssertCalendarFieldValue(
29952995
cal.getAlias(), test_time, "ethiopic-amete-alem",
29962996
0, 7515, 1, 8, 4, 22, 52, 3, 4, 0, 4, 4, 44, 51,
2997-
323, 0, 0, 2015, 3, 2015, 2459885, 17091323, 0);
2997+
323, 0, 0, 7515, 3, 7515, 2459885, 17091323, 0);
29982998
}
29992999

30003000

icu4c/source/test/intltest/dtfmttst.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,6 +4896,24 @@ void DateFormatTest::TestCreateInstanceForSkeleton() {
48964896
result.remove();
48974897
fmt->format(date(98, 5-1, 25), result, pos);
48984898
assertEquals("format yMd", "5/25/1998", result);
4899+
4900+
UnicodeString result2;
4901+
fmt.adoptInstead(DateFormat::createInstanceForSkeleton(
4902+
"yMd", "en-u-ca-ethiopic-amete-alem", status));
4903+
if (!assertSuccess("Create with pattern yMd", status)) {
4904+
return;
4905+
}
4906+
fmt->format(date(98, 5-1, 25), result2, pos);
4907+
assertEquals("format yMd", "9/17/7490 ERA0", result2);
4908+
4909+
fmt.adoptInstead(DateFormat::createInstanceForSkeleton(
4910+
"uMd", "en-u-ca-ethiopic-amete-alem", status));
4911+
if (!assertSuccess("Create with pattern uMd", status)) {
4912+
return;
4913+
}
4914+
result.remove();
4915+
fmt->format(date(98, 5-1, 25), result, pos);
4916+
assertEquals("format uMd", result2, result);
48994917
}
49004918

49014919
void DateFormatTest::TestCreateInstanceForSkeletonDefault() {

icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/DateFormatTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5576,6 +5576,17 @@ public void test20739_MillisecondsWithoutSeconds() {
55765576
}
55775577
}
55785578

5579+
@Test
5580+
public void testExtendedYear() {
5581+
ULocale locale = new ULocale("en-u-ca-ethiopic-amete-alem");
5582+
DateFormat fmt = DateFormat.getInstanceForSkeleton("yMd", locale);
5583+
DateFormat fmt2 = DateFormat.getInstanceForSkeleton("uMd", locale);
5584+
String result = fmt.format(new Date(98, 5-1, 25));
5585+
String result2 = fmt2.format(new Date(98, 5-1, 25));
5586+
assertEquals("Format", "9/17/7490 ERA0", result);
5587+
assertEquals("Format", result, result2);
5588+
}
5589+
55795590
@Test
55805591
public void test20741_ABFields() {
55815592
String [] skeletons = {"EEEEEBBBBB", "EEEEEbbbbb"};

icu4j/main/core/src/main/java/com/ibm/icu/util/EthiopicCalendar.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public final class EthiopicCalendar extends CECalendar
128128
// Julian Days relative to the
129129
// \u12d3\u1218\u1270\u1361\u121d\u1215\u1228\u1275 epoch
130130
// Note: we no longer use this constant
131-
//private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
131+
private static final int JD_EPOCH_OFFSET_AMETE_ALEM = -285019;
132132

133133
// Julian Days relative to the
134134
// \u12d3\u1218\u1270\u1361\u12d3\u1208\u121d epoch
@@ -306,8 +306,7 @@ protected int handleGetExtendedYear() {
306306
if (newerField(EXTENDED_YEAR, YEAR) == EXTENDED_YEAR) {
307307
eyear = internalGet(EXTENDED_YEAR, 1); // Default to year 1
308308
} else if (isAmeteAlemEra()){
309-
eyear = internalGet(YEAR, 1 + AMETE_MIHRET_DELTA)
310-
- AMETE_MIHRET_DELTA; // Default to year 1 of Amelete Mihret
309+
eyear = internalGet(YEAR, 1); // Default to year 1
311310
} else {
312311
// The year defaults to the epoch start, the era to AMETE_MIHRET
313312
int era = internalGet(ERA, AMETE_MIHRET);
@@ -344,7 +343,7 @@ protected int extendedYearToEra(int eyear) {
344343
@Override
345344
protected int extendedYearToYear(int eyear) {
346345
if (isAmeteAlemEra()) {
347-
return eyear + AMETE_MIHRET_DELTA;
346+
return eyear;
348347
} else {
349348
return (eyear <= 0) ? eyear + AMETE_MIHRET_DELTA : eyear;
350349
}
@@ -372,7 +371,7 @@ protected int handleGetLimit(int field, int limitType) {
372371
@Override
373372
@Deprecated
374373
protected int getJDEpochOffset() {
375-
return JD_EPOCH_OFFSET_AMETE_MIHRET;
374+
return isAmeteAlemEra() ? JD_EPOCH_OFFSET_AMETE_ALEM : JD_EPOCH_OFFSET_AMETE_MIHRET;
376375
}
377376

378377
/**
@@ -393,8 +392,6 @@ public static int EthiopicToJD(long year, int month, int date) {
393392
}
394393

395394

396-
private static final int ETHIOPIC_AMETE_ALEM_CALENDAR_RELATED_YEAR_DIFFERENCE = -5492;
397-
398395
private static final int ETHIOPIC_CALENDAR_RELATED_YEAR_DIFFERENCE = 8;
399396

400397
/**
@@ -403,9 +400,7 @@ public static int EthiopicToJD(long year, int month, int date) {
403400
*/
404401
@Deprecated
405402
protected final int getRelatedYearDifference() {
406-
return isAmeteAlemEra() ?
407-
ETHIOPIC_AMETE_ALEM_CALENDAR_RELATED_YEAR_DIFFERENCE :
408-
ETHIOPIC_CALENDAR_RELATED_YEAR_DIFFERENCE;
403+
return ETHIOPIC_CALENDAR_RELATED_YEAR_DIFFERENCE;
409404
}
410405

411406
/**

0 commit comments

Comments
 (0)