mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8317742: ISO Standard Date Format implementation consistency on DateTimeFormatter and String.format
Reviewed-by: rriggs, naoto
This commit is contained in:
parent
c4aba87570
commit
61d81d6496
2 changed files with 83 additions and 2 deletions
|
@ -56,6 +56,7 @@ import java.time.DateTimeException;
|
|||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.chrono.IsoChronology;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.time.temporal.TemporalQueries;
|
||||
|
@ -2050,6 +2051,11 @@ public final class Formatter implements Closeable, Flushable {
|
|||
return locale == null ? ',' : getDecimalFormatSymbols(locale).getGroupingSeparator();
|
||||
}
|
||||
|
||||
// Use minus sign from cached DecimalFormatSymbols.
|
||||
private static char getMinusSign(Locale locale) {
|
||||
return locale == null ? '-' : getDecimalFormatSymbols(locale).getMinusSign();
|
||||
}
|
||||
|
||||
private Appendable a;
|
||||
private final Locale l;
|
||||
private IOException lastException;
|
||||
|
@ -4490,7 +4496,20 @@ public final class Formatter implements Closeable, Flushable {
|
|||
}
|
||||
case DateTime.ISO_STANDARD_DATE: { // 'F' (%Y-%m-%d)
|
||||
char sep = '-';
|
||||
print(fmt, sb, t, DateTime.YEAR_4, l).append(sep);
|
||||
ChronoField yearField;
|
||||
if (t.query(TemporalQueries.chronology()) instanceof IsoChronology) {
|
||||
yearField = ChronoField.YEAR;
|
||||
} else {
|
||||
yearField = ChronoField.YEAR_OF_ERA;
|
||||
}
|
||||
int year = t.get(yearField);
|
||||
if (year < 0) {
|
||||
sb.append(getMinusSign(l));
|
||||
year = -year;
|
||||
} else if (year > 9999) {
|
||||
sb.append('+');
|
||||
}
|
||||
sb.append(localizedMagnitude(fmt, null, year, Flags.ZERO_PAD, 4, l)).append(sep);
|
||||
print(fmt, sb, t, DateTime.MONTH, l).append(sep);
|
||||
print(fmt, sb, t, DateTime.DAY_OF_MONTH_0, l);
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue