Skip to content

Commit b9b952c

Browse files
committed
ICU-23056 Integrate CLDR 48 m2 to ICU main, part 3: ICU code/test/tool mods
1 parent bde6a56 commit b9b952c

File tree

7 files changed

+67
-31
lines changed

7 files changed

+67
-31
lines changed

icu4c/source/i18n/erarules.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,8 @@ EraRules* EraRules::createInstance(const char *calType, UBool includeTentativeEr
192192
}
193193
} else {
194194
if (hasEnd) {
195-
if (eraIdx != 0) {
196-
// This implementation does not support end only rule for eras other than
197-
// the first one.
198-
status = U_INVALID_FORMAT_ERROR;
199-
return nullptr;
200-
}
201-
U_ASSERT(eraIdx == 0);
195+
// The islamic calendars now have an end-only rule for the
196+
// second (and final) entry; basically they are in reverse order.
202197
startDates[eraIdx] = MIN_ENCODED_START;
203198
} else {
204199
status = U_INVALID_FORMAT_ERROR;
@@ -267,6 +262,15 @@ int32_t EraRules::getEraIndex(int32_t year, int32_t month, int32_t day, UErrorCo
267262
status = U_ILLEGAL_ARGUMENT_ERROR;
268263
return -1;
269264
}
265+
if (numEras > 1 && startDates[numEras-1] == MIN_ENCODED_START) {
266+
// Multiple eras in reverse order, linear search from beginning.
267+
// Currently only for islamic.
268+
for (int eraIdx = 0; eraIdx < numEras; eraIdx++) {
269+
if (compareEncodedDateWithYMD(startDates[eraIdx], year, month, day) <= 0) {
270+
return eraIdx;
271+
}
272+
}
273+
}
270274
int32_t high = numEras; // last index + 1
271275
int32_t low;
272276

@@ -311,14 +315,26 @@ void EraRules::initCurrentEra() {
311315
if (U_FAILURE(ec)) return;
312316
int currentEncodedDate = encodeDate(year, month0 + 1 /* changes to 1-base */, dom);
313317
int eraIdx = numEras - 1;
314-
while (eraIdx > 0) {
315-
if (currentEncodedDate >= startDates[eraIdx]) {
316-
break;
318+
if (eraIdx > 0 && startDates[eraIdx] == MIN_ENCODED_START) {
319+
// Multiple eras in reverse order, search from beginning.
320+
// Currently only for islamic. Here current era must be
321+
// in the array.
322+
for (eraIdx = 0; eraIdx < numEras; eraIdx++) {
323+
if (currentEncodedDate >= startDates[eraIdx]) {
324+
break;
325+
}
326+
}
327+
} else {
328+
// The usual behavior, search from end
329+
while (eraIdx > 0) {
330+
if (currentEncodedDate >= startDates[eraIdx]) {
331+
break;
332+
}
333+
eraIdx--;
317334
}
318-
eraIdx--;
335+
// Note: current era could be before the first era.
336+
// In this case, this implementation returns the first era index (0).
319337
}
320-
// Note: current era could be before the first era.
321-
// In this case, this implementation returns the first era index (0).
322338
currentEra = eraIdx;
323339
}
324340

icu4c/source/test/intltest/dtptngts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,8 @@ void IntlTestDateTimePatternGeneratorAPI::testJjMapping() {
13741374
errln("FAIL: DateTimePatternGenerator::staticGetSkeleton locale %s: %s", localeID, u_errorName(status));
13751375
continue;
13761376
}
1377-
if (uprv_strcmp(localeID, "ku_SY")==0) {
1378-
logKnownIssue("CLDR-18495", "ku_SY needs Gregorian standard time patterns using 'h'");
1377+
if (uprv_strcmp(localeID, "ku_Latn_IQ")==0) {
1378+
logKnownIssue("CLDR-18495", "ku_Latn_IQ needs either 'h' in Grego std time patterns or timeData update");
13791379
continue;
13801380
}
13811381
const char16_t* charPtr = timeCycleChars;

icu4c/source/test/testdata/structLocale.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40195,12 +40195,15 @@ structLocale:table(nofallback){
4019540195
eras{
4019640196
abbreviated{
4019740197
"",
40198+
"",
4019840199
}
4019940200
wide{
4020040201
"",
40202+
"",
4020140203
}
4020240204
narrow{
4020340205
"",
40206+
"",
4020440207
}
4020540208
}
4020640209
intervalFormats{

icu4j/main/core/src/main/java/com/ibm/icu/impl/EraRules.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ public static EraRules getInstance(CalType calType, boolean includeTentativeEra)
9595
}
9696
} else {
9797
if (hasEnd) {
98-
if (eraIdx != 0) {
99-
// This implementation does not support end only rule for eras other than
100-
// the first one.
101-
throw new ICUException(
102-
"Era data for " + eraIdxStr + " in era rule data for " + calType.getId()
103-
+ " has only end rule.");
104-
}
98+
// The islamic calendars now have an end-only rule for the
99+
// second (and final) entry; basically they are in reverse order.
105100
startDates[eraIdx] = MIN_ENCODED_START;
106101
} else {
107102
throw new ICUException("Missing era start/end rule date for key:" + eraIdxStr + " in era rule data for "
@@ -177,6 +172,15 @@ public int getEraIndex(int year, int month, int day) {
177172
if (month < 1 || month > 12 || day < 1 || day > 31) {
178173
throw new IllegalArgumentException("Illegal date - year:" + year + "month:" + month + "day:" + day);
179174
}
175+
if (numEras > 1 && startDates[numEras-1] == MIN_ENCODED_START) {
176+
// Multiple eras in reverse order, linear search from beginning.
177+
// Currently only for islamic.
178+
for (int eraIdx = 0; eraIdx < numEras; eraIdx++) {
179+
if (compareEncodedDateWithYMD(startDates[eraIdx], year, month, day) <= 0) {
180+
return eraIdx;
181+
}
182+
}
183+
}
180184
int high = numEras; // last index + 1
181185
int low;
182186

@@ -219,14 +223,26 @@ private void initCurrentEra() {
219223
int[] fields = Grego.timeToFields(localMillis, null);
220224
int currentEncodedDate = encodeDate(fields[0], fields[1] + 1 /* changes to 1-base */, fields[2]);
221225
int eraIdx = numEras - 1;
222-
while (eraIdx > 0) {
223-
if (currentEncodedDate >= startDates[eraIdx]) {
224-
break;
226+
if (eraIdx > 0 && startDates[eraIdx] == MIN_ENCODED_START) {
227+
// Multiple eras in reverse order, search from beginning.
228+
// Currently only for islamic. Here current era must be
229+
// in the array.
230+
for (eraIdx = 0; eraIdx < numEras; eraIdx++) {
231+
if (currentEncodedDate >= startDates[eraIdx]) {
232+
break;
233+
}
234+
}
235+
} else {
236+
// The usual behavior, search from end
237+
while (eraIdx > 0) {
238+
if (currentEncodedDate >= startDates[eraIdx]) {
239+
break;
240+
}
241+
eraIdx--;
225242
}
226-
eraIdx--;
243+
// Note: current era could be before the first era.
244+
// In this case, this implementation returns the first era index (0).
227245
}
228-
// Note: current era could be before the first era.
229-
// In this case, this implementation returns the first era index (0).
230246
currentEra = eraIdx;
231247
}
232248

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/JavaTimeFormatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void testNonGregorianDateFormatting() {
129129
"chinese", "Eighth Month 23, 2013(gui-si)",
130130
"hebrew", "23 Tishri 5774 AM",
131131
"indian", "Asvina 5, 1935 Saka",
132-
"islamic", "Dhuʻl-Qiʻdah 22, 1434 AH",
132+
"islamic", "Dhuʻl-Qiʻdah 22, 1434 Anno Hegirae",
133133
"japanese", "September 27, 25 Heisei",
134134
"persian", "Mehr 5, 1392 AP",
135135
"roc", "September 27, 102 Minguo",

tools/cldr/cldr-to-icu/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
// K
5252
ka, kab, kam, kde, kea, kgp, khq, ki, kk, kkj, kl, kln, km, kn, ko, kok, kok_Latn, ks
53-
ks_Deva, ks_IN, ksb, ksf, ksh, ku, kw, kxv, kxv_Deva, kxv_IN, kxv_Orya, kxv_Telu, ky
53+
ks_Deva, ks_IN, ksb, ksf, ksh, ku, ku_SY, kw, kxv, kxv_Deva, kxv_IN, kxv_Orya, kxv_Telu, ky
5454

5555
// L
5656
lag, lb, lg, lij, lkt, lmo, ln, lo, lrc, lt, lu, luo, luy, lv
@@ -140,7 +140,7 @@
140140
root,
141141

142142
// A-B
143-
af, am, ars, ar, as, az, be, bg, bn, bo, br, bs_Cyrl, bs,
143+
af, am, ars, ar, as, az, be, bg, blo, bn, bo, br, bs_Cyrl, bs,
144144

145145
// C-F
146146
ca, ceb, chr, cs, cy, da, de_AT, de, dsb, dz, ee, el, en,

tools/cldr/cldr-to-icu/src/main/resources/ldml2icu_locale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@
273273
//ldml/localeDisplayNames/keys/key[@type="(%A)"] ; /Keys/$1
274274

275275
//ldml/localeDisplayNames/languages/language[@type="(%A)"][@alt="(%A)"] ; /Languages%$2/$1
276+
//ldml/localeDisplayNames/languages/language[@type="(%A)"][@menu="(%A)"] ; /Languages%$2/$1
276277
//ldml/localeDisplayNames/languages/language[@type="(%A)"] ; /Languages/$1
277278

278279
//ldml/localeDisplayNames/localeDisplayPattern/localeKeyTypePattern ; /localeDisplayPattern/keyTypePattern

0 commit comments

Comments
 (0)