4646import static java .time .temporal .ChronoField .DAY_OF_WEEK ;
4747import static java .time .temporal .ChronoField .DAY_OF_YEAR ;
4848import static java .time .temporal .ChronoField .HOUR_OF_DAY ;
49- import static java .time .temporal .ChronoField .MILLI_OF_SECOND ;
5049import static java .time .temporal .ChronoField .MINUTE_OF_HOUR ;
5150import static java .time .temporal .ChronoField .MONTH_OF_YEAR ;
5251import static java .time .temporal .ChronoField .NANO_OF_SECOND ;
@@ -90,7 +89,7 @@ public class DateFormatters {
9089 .appendLiteral ('T' )
9190 .append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
9291 .optionalStart ()
93- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
92+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
9493 .optionalEnd ()
9594 .optionalStart ()
9695 .appendZoneOrOffsetId ()
@@ -159,14 +158,14 @@ public class DateFormatters {
159158 .appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
160159 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
161160 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
162- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
161+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
163162 .toFormatter (Locale .ROOT );
164163
165164 private static final DateTimeFormatter BASIC_TIME_PRINTER = new DateTimeFormatterBuilder ()
166165 .appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
167166 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
168167 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
169- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
168+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
170169 .toFormatter (Locale .ROOT );
171170
172171 /*
@@ -372,7 +371,7 @@ public class DateFormatters {
372371 .appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
373372 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
374373 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
375- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
374+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
376375 .appendZoneOrOffsetId ()
377376 .toFormatter (Locale .ROOT ),
378377 new DateTimeFormatterBuilder ()
@@ -381,7 +380,7 @@ public class DateFormatters {
381380 .appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
382381 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
383382 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
384- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
383+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
385384 .append (TIME_ZONE_FORMATTER_NO_COLON )
386385 .toFormatter (Locale .ROOT )
387386 );
@@ -438,7 +437,7 @@ public class DateFormatters {
438437 .appendLiteral ('T' )
439438 .append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
440439 .optionalStart ()
441- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
440+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
442441 .optionalEnd ()
443442 .toFormatter (Locale .ROOT );
444443
@@ -495,12 +494,12 @@ public class DateFormatters {
495494 // NOTE: this is not a strict formatter to retain the joda time based behaviour, even though it's named like this
496495 private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder ()
497496 .append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
498- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
497+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
499498 .toFormatter (Locale .ROOT );
500499
501500 private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER = new DateTimeFormatterBuilder ()
502501 .append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
503- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
502+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
504503 .toFormatter (Locale .ROOT );
505504
506505 /*
@@ -534,7 +533,7 @@ public class DateFormatters {
534533 .appendLiteral ("T" )
535534 .append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
536535 // this one here is lenient as well to retain joda time based bwc compatibility
537- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
536+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
538537 .toFormatter (Locale .ROOT )
539538 );
540539
@@ -562,7 +561,7 @@ public class DateFormatters {
562561 .optionalStart ()
563562 .appendLiteral (':' )
564563 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
565- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
564+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
566565 .optionalEnd ()
567566 .toFormatter (Locale .ROOT );
568567
@@ -586,7 +585,7 @@ public class DateFormatters {
586585 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
587586 .appendLiteral (':' )
588587 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
589- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
588+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
590589 .toFormatter (Locale .ROOT );
591590
592591 private static final DateTimeFormatter STRICT_TIME_PRINTER = new DateTimeFormatterBuilder ()
@@ -595,7 +594,7 @@ public class DateFormatters {
595594 .appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
596595 .appendLiteral (':' )
597596 .appendValue (SECOND_OF_MINUTE , 2 , 2 , SignStyle .NOT_NEGATIVE )
598- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
597+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
599598 .toFormatter (Locale .ROOT );
600599
601600 /*
@@ -819,7 +818,7 @@ public class DateFormatters {
819818 .appendValue (SECOND_OF_MINUTE , 1 , 2 , SignStyle .NOT_NEGATIVE )
820819 .optionalEnd ()
821820 .optionalStart ()
822- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
821+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
823822 .optionalEnd ()
824823 .optionalStart ().appendZoneOrOffsetId ().optionalEnd ()
825824 .optionalStart ().appendOffset ("+HHmm" , "Z" ).optionalEnd ()
@@ -840,7 +839,7 @@ public class DateFormatters {
840839 .appendValue (MINUTE_OF_HOUR , 1 , 2 , SignStyle .NOT_NEGATIVE )
841840 .appendLiteral (':' )
842841 .appendValue (SECOND_OF_MINUTE , 1 , 2 , SignStyle .NOT_NEGATIVE )
843- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
842+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
844843 .toFormatter (Locale .ROOT );
845844
846845 private static final DateTimeFormatter ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder ()
@@ -875,7 +874,7 @@ public class DateFormatters {
875874
876875 private static final DateTimeFormatter TIME_PREFIX = new DateTimeFormatterBuilder ()
877876 .append (TIME_NO_MILLIS_FORMATTER )
878- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
877+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
879878 .toFormatter (Locale .ROOT );
880879
881880 private static final DateTimeFormatter WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder ()
@@ -963,7 +962,7 @@ public class DateFormatters {
963962 .optionalStart ()
964963 .appendLiteral (':' )
965964 .appendValue (SECOND_OF_MINUTE , 1 , 2 , SignStyle .NOT_NEGATIVE )
966- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
965+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
967966 .optionalEnd ()
968967 .toFormatter (Locale .ROOT );
969968
@@ -1068,7 +1067,7 @@ public class DateFormatters {
10681067 .optionalStart ()
10691068 .appendLiteral (':' )
10701069 .appendValue (SECOND_OF_MINUTE , 1 , 2 , SignStyle .NOT_NEGATIVE )
1071- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
1070+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
10721071 .optionalEnd ()
10731072 .toFormatter (Locale .ROOT );
10741073
@@ -1453,18 +1452,21 @@ static JavaDateFormatter merge(String pattern, List<DateFormatter> formatters) {
14531452 assert formatters .size () > 0 ;
14541453
14551454 List <DateTimeFormatter > dateTimeFormatters = new ArrayList <>(formatters .size ());
1455+ DateTimeFormatterBuilder roundupBuilder = new DateTimeFormatterBuilder ();
14561456 DateTimeFormatter printer = null ;
14571457 for (DateFormatter formatter : formatters ) {
14581458 assert formatter instanceof JavaDateFormatter ;
14591459 JavaDateFormatter javaDateFormatter = (JavaDateFormatter ) formatter ;
1460- DateTimeFormatter dateTimeFormatter = javaDateFormatter .getParser ();
14611460 if (printer == null ) {
14621461 printer = javaDateFormatter .getPrinter ();
14631462 }
1464- dateTimeFormatters .add (dateTimeFormatter );
1463+ dateTimeFormatters .add (javaDateFormatter .getParser ());
1464+ roundupBuilder .appendOptional (javaDateFormatter .getRoundupParser ());
14651465 }
1466+ DateTimeFormatter roundUpParser = roundupBuilder .toFormatter (Locale .ROOT );
14661467
1467- return new JavaDateFormatter (pattern , printer , dateTimeFormatters .toArray (new DateTimeFormatter [0 ]));
1468+ return new JavaDateFormatter (pattern , printer , builder -> builder .append (roundUpParser ),
1469+ dateTimeFormatters .toArray (new DateTimeFormatter [0 ]));
14681470 }
14691471
14701472 private static final ZonedDateTime EPOCH_ZONED_DATE_TIME = Instant .EPOCH .atZone (ZoneOffset .UTC );
0 commit comments