From 44bacd0b0201fd784f831212f818d32c1e93d299 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 17 Mar 2021 22:41:01 +0300 Subject: [PATCH] java.time: update threeten code and tests WRT JDK semantics --- .../bp/format/DateTimeFormatterBuilder.java | 9 ++++++- .../format/TestDateTimeFormatterBuilder.java | 24 +++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java index a1334122e..a6a5c2726 100644 --- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java +++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java @@ -1672,12 +1672,19 @@ public final class DateTimeFormatterBuilder { case 'D': if (count == 1) { appendValue(field); - } else if (count <= 3) { + } else if (count == 2) { + appendValue(field, 2, 3, SignStyle.NOT_NEGATIVE); + } else if (count == 3) { appendValue(field, count); } else { throw new IllegalArgumentException("Too many pattern letters: " + cur); } break; + case 'N': + case 'n': + case 'A': + appendValue(field, count, 19, SignStyle.NOT_NEGATIVE); + break; default: if (count == 1) { appendValue(field); diff --git a/tests/src/test/java/org/teavm/classlib/java/time/format/TestDateTimeFormatterBuilder.java b/tests/src/test/java/org/teavm/classlib/java/time/format/TestDateTimeFormatterBuilder.java index db35c1249..6787ec61e 100644 --- a/tests/src/test/java/org/teavm/classlib/java/time/format/TestDateTimeFormatterBuilder.java +++ b/tests/src/test/java/org/teavm/classlib/java/time/format/TestDateTimeFormatterBuilder.java @@ -417,8 +417,6 @@ public class TestDateTimeFormatterBuilder { {"HH:MM:ss"}, {"HHMMSS"}, {"HH:MM:SS"}, - {"+H"}, - {"+HMM"}, {"+HHM"}, {"+A"}, }; @@ -619,7 +617,7 @@ public class TestDateTimeFormatterBuilder { // {"www", "Value(WeekOfWeekBasedYear,3)"}, {"D", "Value(DayOfYear)"}, - {"DD", "Value(DayOfYear,2)"}, + {"DD", "Value(DayOfYear,2,3,NOT_NEGATIVE)"}, {"DDD", "Value(DayOfYear,3)"}, {"d", "Value(DayOfMonth)"}, @@ -658,17 +656,17 @@ public class TestDateTimeFormatterBuilder { {"SSS", "Fraction(NanoOfSecond,3,3)"}, {"SSSSSSSSS", "Fraction(NanoOfSecond,9,9)"}, - {"A", "Value(MilliOfDay)"}, - {"AA", "Value(MilliOfDay,2)"}, - {"AAA", "Value(MilliOfDay,3)"}, + {"A", "Value(MilliOfDay,1,19,NOT_NEGATIVE)"}, + {"AA", "Value(MilliOfDay,2,19,NOT_NEGATIVE)"}, + {"AAA", "Value(MilliOfDay,3,19,NOT_NEGATIVE)"}, - {"n", "Value(NanoOfSecond)"}, - {"nn", "Value(NanoOfSecond,2)"}, - {"nnn", "Value(NanoOfSecond,3)"}, + {"n", "Value(NanoOfSecond,1,19,NOT_NEGATIVE)"}, + {"nn", "Value(NanoOfSecond,2,19,NOT_NEGATIVE)"}, + {"nnn", "Value(NanoOfSecond,3,19,NOT_NEGATIVE)"}, - {"N", "Value(NanoOfDay)"}, - {"NN", "Value(NanoOfDay,2)"}, - {"NNN", "Value(NanoOfDay,3)"}, + {"N", "Value(NanoOfDay,1,19,NOT_NEGATIVE)"}, + {"NN", "Value(NanoOfDay,2,19,NOT_NEGATIVE)"}, + {"NNN", "Value(NanoOfDay,3,19,NOT_NEGATIVE)"}, {"z", "ZoneText(SHORT)"}, {"zz", "ZoneText(SHORT)"}, @@ -694,7 +692,7 @@ public class TestDateTimeFormatterBuilder { {"xxxxx", "Offset(+HH:MM:ss,'+00:00')"}, {"ppH", "Pad(Value(HourOfDay),2)"}, - {"pppDD", "Pad(Value(DayOfYear,2),3)"}, + {"pppDD", "Pad(Value(DayOfYear,2,3,NOT_NEGATIVE),3)"}, {"uuuu[-MM[-dd", "Value(Year,4,19,EXCEEDS_PAD)['-'Value(MonthOfYear,2)['-'Value(DayOfMonth,2)]]"}, {"uuuu[-MM[-dd]]", "Value(Year,4,19,EXCEEDS_PAD)['-'Value(MonthOfYear,2)['-'Value(DayOfMonth,2)]]"},