// does), return NULL.
if(U_FAILURE(errorCode)) { return NULL; }
- const char *localeCode = locale.getName();
+ const char *localeCode = locale.getBaseName();
char name[ULOC_FULLNAME_CAPACITY];
char parentName[ULOC_FULLNAME_CAPACITY];
sdf.applyPattern(UnicodeString("hh:mm:ss BBBB"));
assertEquals("hh:mm:ss BBBB | 01:00:00 | es", "01:00:00 de la madrugada",
sdf.format(k010000, out.remove()));
+
+ // #13215: for locales with keywords, check hang in DayPeriodRules""getInstance(const Locale, ...),
+ // which is called in SimpleDateFormat::format for patterns that include 'B'.
+ sdf = SimpleDateFormat(UnicodeString(), Locale("en@calendar=buddhist"), errorCode);
+ sdf.setTimeZone(*tz);
+
+ sdf.applyPattern(UnicodeString("hh:mm:ss BBBB"));
+ assertEquals("hh:mm:ss BBBB | 01:00:00 | en@calendar=buddhist", "01:00:00 at night",
+ sdf.format(k010000, out.remove()));
}
void DateFormatTest::TestMinuteSecondFieldsInOddPlaces() {
* @return a DayPeriodRules object for `locale`.
*/
public static DayPeriodRules getInstance(ULocale locale) {
- String localeCode = locale.getName();
+ String localeCode = locale.getBaseName();
if (localeCode.isEmpty()) { localeCode = "root"; }
Integer ruleSetNum = null;
sdf.applyPattern("hh:mm:ss BBBB");
assertEquals("hh:mm:ss BBBB | 01:00:00 | es", "01:00:00 de la madrugada", sdf.format(k010000));
+
+ // #13215: for locales with keywords, check hang in DayPeriodRules.getInstance(ULocale),
+ // which is called in SimpleDateFormat.format for patterns that include 'B'.
+ sdf = new SimpleDateFormat("", new ULocale("en@calendar=buddhist"));
+ sdf.setTimeZone(TimeZone.GMT_ZONE);
+
+ sdf.applyPattern("hh:mm:ss BBBB");
+ assertEquals("hh:mm:ss BBBB | 01:00:00 | en@calendar=buddhist", "01:00:00 at night", sdf.format(k010000));
}
@Test