mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
ICU-22202 Fixed DateIntervalFormat to solve a couple "conflicting fields" errors.
This commit is contained in:
parent
b396885aae
commit
2b6ddc50fe
3 changed files with 38 additions and 1 deletions
|
@ -2386,6 +2386,22 @@ void DateIntervalFormatTest::testTicket21939() {
|
|||
UnicodeString pattern;
|
||||
assertEquals("Wrong pattern", u"M/d/r, h:mm\u202Fa", sdf->toPattern(pattern));
|
||||
}
|
||||
|
||||
// additional tests for the related ICU-22202
|
||||
dif.adoptInstead(DateIntervalFormat::createInstance(u"Lh", Locale::getEnglish(), err));
|
||||
if (assertSuccess("Error creating DateIntervalFormat", err)) {
|
||||
const DateFormat* df = dif->getDateFormat();
|
||||
const SimpleDateFormat* sdf = dynamic_cast<const SimpleDateFormat*>(df);
|
||||
UnicodeString pattern;
|
||||
assertEquals("Wrong pattern", u"L, h\u202Fa", sdf->toPattern(pattern));
|
||||
}
|
||||
dif.adoptInstead(DateIntervalFormat::createInstance(u"UH", Locale::forLanguageTag("en-u-ca-chinese", err), err));
|
||||
if (assertSuccess("Error creating DateIntervalFormat", err)) {
|
||||
const DateFormat* df = dif->getDateFormat();
|
||||
const SimpleDateFormat* sdf = dynamic_cast<const SimpleDateFormat*>(df);
|
||||
UnicodeString pattern;
|
||||
assertEquals("Wrong pattern", u"r(U), HH", sdf->toPattern(pattern));
|
||||
}
|
||||
}
|
||||
|
||||
void DateIntervalFormatTest::testTicket20710_FieldIdentity() {
|
||||
|
|
|
@ -2308,7 +2308,17 @@ public class DateIntervalFormat extends UFormat {
|
|||
private static boolean fieldExistsInSkeleton(int field, String skeleton)
|
||||
{
|
||||
String fieldChar = DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field];
|
||||
return ( (skeleton.indexOf(fieldChar) == -1) ? false : true ) ;
|
||||
boolean result = skeleton.contains(fieldChar);
|
||||
if (!result) {
|
||||
if (fieldChar.equals("M")) {
|
||||
// if the caller specified Calendar.MONTH, check the pattern for both M and L
|
||||
result = skeleton.contains("L");
|
||||
} else if (fieldChar.equals("y")) {
|
||||
// if the caller specified Calendar.YEAR, check the pattern for y, Y, u, U, and r
|
||||
result = skeleton.contains("U") || skeleton.contains("Y") || skeleton.contains("u") || skeleton.contains("r");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2493,6 +2493,17 @@ public class DateIntervalFormatTest extends CoreTestFmwk {
|
|||
DateFormat df = dif.getDateFormat();
|
||||
SimpleDateFormat sdf = (SimpleDateFormat)df;
|
||||
assertEquals("Wrong date format", "M/d/r, h:mm\u202Fa", sdf.toPattern());
|
||||
|
||||
// additional tests for the related ICU-22202
|
||||
dif = DateIntervalFormat.getInstance("Lh", ULocale.ENGLISH);
|
||||
df = dif.getDateFormat();
|
||||
sdf = (SimpleDateFormat)df;
|
||||
assertEquals("Wrong date format", "L, h a", sdf.toPattern());
|
||||
|
||||
dif = DateIntervalFormat.getInstance("UH", ULocale.forLanguageTag("en-u-ca-chinese"));
|
||||
df = dif.getDateFormat();
|
||||
sdf = (SimpleDateFormat)df;
|
||||
assertEquals("Wrong date format", "r(U), HH", sdf.toPattern());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue