mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8246662: Test java/time/test/java/time/format/TestUnicodeExtension.java failed on japanese locale
Reviewed-by: rriggs, joehw
This commit is contained in:
parent
140a79765f
commit
27e168677f
2 changed files with 33 additions and 22 deletions
|
@ -1469,7 +1469,7 @@ public final class DateTimeFormatter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of this formatter with localized values of the locale,
|
* Returns a copy of this formatter with localized values of the locale,
|
||||||
* calendar, region, decimal style and/or timezone, that supercede values in
|
* calendar, region, decimal style and/or timezone, that supersede values in
|
||||||
* this formatter.
|
* this formatter.
|
||||||
* <p>
|
* <p>
|
||||||
* This is used to lookup any part of the formatter needing specific
|
* This is used to lookup any part of the formatter needing specific
|
||||||
|
@ -1489,16 +1489,12 @@ public final class DateTimeFormatter {
|
||||||
*
|
*
|
||||||
* @param locale the locale, not null
|
* @param locale the locale, not null
|
||||||
* @return a formatter based on this formatter with localized values of
|
* @return a formatter based on this formatter with localized values of
|
||||||
* the calendar, decimal style and/or timezone, that supercede values in this
|
* the calendar, decimal style and/or timezone, that supersede values in this
|
||||||
* formatter.
|
* formatter.
|
||||||
* @see #withLocale(Locale)
|
* @see #withLocale(Locale)
|
||||||
* @since 10
|
* @since 10
|
||||||
*/
|
*/
|
||||||
public DateTimeFormatter localizedBy(Locale locale) {
|
public DateTimeFormatter localizedBy(Locale locale) {
|
||||||
if (this.locale.equals(locale)) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override decimalStyle/chronology/timezone for the locale object
|
// Override decimalStyle/chronology/timezone for the locale object
|
||||||
String tzType = locale.getUnicodeLocaleType("tz");
|
String tzType = locale.getUnicodeLocaleType("tz");
|
||||||
ZoneId z = tzType != null ?
|
ZoneId z = tzType != null ?
|
||||||
|
@ -1506,13 +1502,16 @@ public final class DateTimeFormatter {
|
||||||
.map(ZoneId::of)
|
.map(ZoneId::of)
|
||||||
.orElse(zone) :
|
.orElse(zone) :
|
||||||
zone;
|
zone;
|
||||||
return new DateTimeFormatter(printerParser,
|
Chronology c = Chronology.ofLocale(locale);
|
||||||
locale,
|
DecimalStyle ds = DecimalStyle.of(locale);
|
||||||
DecimalStyle.of(locale),
|
if (this.locale.equals(locale) &&
|
||||||
resolverStyle,
|
c.equals(chrono) &&
|
||||||
resolverFields,
|
ds.equals(decimalStyle) &&
|
||||||
Chronology.ofLocale(locale),
|
Objects.equals(z, zone)) {
|
||||||
z);
|
return this;
|
||||||
|
} else {
|
||||||
|
return new DateTimeFormatter(printerParser, locale, ds, resolverStyle, resolverFields, c, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
|
@ -47,6 +47,7 @@ import java.time.temporal.TemporalField;
|
||||||
import java.time.temporal.WeekFields;
|
import java.time.temporal.WeekFields;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.testng.annotations.AfterTest;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -825,15 +826,26 @@ public class TestUnicodeExtension {
|
||||||
public void test_localizedBy(Locale locale, Chronology chrono, ZoneId zone,
|
public void test_localizedBy(Locale locale, Chronology chrono, ZoneId zone,
|
||||||
Chronology chronoExpected, ZoneId zoneExpected,
|
Chronology chronoExpected, ZoneId zoneExpected,
|
||||||
String formatExpected) {
|
String formatExpected) {
|
||||||
DateTimeFormatter dtf =
|
// try this test both with the implicit default locale, and explicit default locale ja-JP
|
||||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL)
|
Locale def = Locale.getDefault();
|
||||||
.withChronology(chrono).withZone(zone).localizedBy(locale);
|
try {
|
||||||
assertEquals(dtf.getChronology(), chronoExpected);
|
Stream.of(def, Locale.JAPAN).forEach(l -> {
|
||||||
assertEquals(dtf.getZone(), zoneExpected);
|
System.out.println(" Testing with the default locale: " + l);
|
||||||
String formatted = dtf.format(ZDT);
|
Locale.setDefault(l);
|
||||||
assertEquals(formatted, formatExpected);
|
|
||||||
assertEquals(dtf.parse(formatted, ZonedDateTime::from),
|
DateTimeFormatter dtf =
|
||||||
zoneExpected != null ? ZDT.withZoneSameInstant(zoneExpected) : ZDT);
|
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL)
|
||||||
|
.withChronology(chrono).withZone(zone).localizedBy(locale);
|
||||||
|
assertEquals(dtf.getChronology(), chronoExpected);
|
||||||
|
assertEquals(dtf.getZone(), zoneExpected);
|
||||||
|
String formatted = dtf.format(ZDT);
|
||||||
|
assertEquals(formatted, formatExpected);
|
||||||
|
assertEquals(dtf.parse(formatted, ZonedDateTime::from),
|
||||||
|
zoneExpected != null ? ZDT.withZoneSameInstant(zoneExpected) : ZDT);
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
Locale.setDefault(def);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider="withLocale")
|
@Test(dataProvider="withLocale")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue