46
46
import static java .time .temporal .ChronoField .DAY_OF_WEEK ;
47
47
import static java .time .temporal .ChronoField .DAY_OF_YEAR ;
48
48
import static java .time .temporal .ChronoField .HOUR_OF_DAY ;
49
- import static java .time .temporal .ChronoField .MILLI_OF_SECOND ;
50
49
import static java .time .temporal .ChronoField .MINUTE_OF_HOUR ;
51
50
import static java .time .temporal .ChronoField .MONTH_OF_YEAR ;
52
51
import static java .time .temporal .ChronoField .NANO_OF_SECOND ;
@@ -90,7 +89,7 @@ public class DateFormatters {
90
89
.appendLiteral ('T' )
91
90
.append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
92
91
.optionalStart ()
93
- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
92
+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
94
93
.optionalEnd ()
95
94
.optionalStart ()
96
95
.appendZoneOrOffsetId ()
@@ -159,14 +158,14 @@ public class DateFormatters {
159
158
.appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
160
159
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
161
160
.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 )
163
162
.toFormatter (Locale .ROOT );
164
163
165
164
private static final DateTimeFormatter BASIC_TIME_PRINTER = new DateTimeFormatterBuilder ()
166
165
.appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
167
166
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
168
167
.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 )
170
169
.toFormatter (Locale .ROOT );
171
170
172
171
/*
@@ -372,7 +371,7 @@ public class DateFormatters {
372
371
.appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
373
372
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
374
373
.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 )
376
375
.appendZoneOrOffsetId ()
377
376
.toFormatter (Locale .ROOT ),
378
377
new DateTimeFormatterBuilder ()
@@ -381,7 +380,7 @@ public class DateFormatters {
381
380
.appendValue (HOUR_OF_DAY , 2 , 2 , SignStyle .NOT_NEGATIVE )
382
381
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
383
382
.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 )
385
384
.append (TIME_ZONE_FORMATTER_NO_COLON )
386
385
.toFormatter (Locale .ROOT )
387
386
);
@@ -438,7 +437,7 @@ public class DateFormatters {
438
437
.appendLiteral ('T' )
439
438
.append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
440
439
.optionalStart ()
441
- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
440
+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
442
441
.optionalEnd ()
443
442
.toFormatter (Locale .ROOT );
444
443
@@ -495,12 +494,12 @@ public class DateFormatters {
495
494
// NOTE: this is not a strict formatter to retain the joda time based behaviour, even though it's named like this
496
495
private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_FORMATTER = new DateTimeFormatterBuilder ()
497
496
.append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
498
- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
497
+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
499
498
.toFormatter (Locale .ROOT );
500
499
501
500
private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_MILLIS_PRINTER = new DateTimeFormatterBuilder ()
502
501
.append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
503
- .appendFraction (MILLI_OF_SECOND , 3 , 3 , true )
502
+ .appendFraction (NANO_OF_SECOND , 3 , 3 , true )
504
503
.toFormatter (Locale .ROOT );
505
504
506
505
/*
@@ -534,7 +533,7 @@ public class DateFormatters {
534
533
.appendLiteral ("T" )
535
534
.append (STRICT_HOUR_MINUTE_SECOND_FORMATTER )
536
535
// 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 )
538
537
.toFormatter (Locale .ROOT )
539
538
);
540
539
@@ -562,7 +561,7 @@ public class DateFormatters {
562
561
.optionalStart ()
563
562
.appendLiteral (':' )
564
563
.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 )
566
565
.optionalEnd ()
567
566
.toFormatter (Locale .ROOT );
568
567
@@ -586,7 +585,7 @@ public class DateFormatters {
586
585
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
587
586
.appendLiteral (':' )
588
587
.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 )
590
589
.toFormatter (Locale .ROOT );
591
590
592
591
private static final DateTimeFormatter STRICT_TIME_PRINTER = new DateTimeFormatterBuilder ()
@@ -595,7 +594,7 @@ public class DateFormatters {
595
594
.appendValue (MINUTE_OF_HOUR , 2 , 2 , SignStyle .NOT_NEGATIVE )
596
595
.appendLiteral (':' )
597
596
.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 )
599
598
.toFormatter (Locale .ROOT );
600
599
601
600
/*
@@ -819,7 +818,7 @@ public class DateFormatters {
819
818
.appendValue (SECOND_OF_MINUTE , 1 , 2 , SignStyle .NOT_NEGATIVE )
820
819
.optionalEnd ()
821
820
.optionalStart ()
822
- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
821
+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
823
822
.optionalEnd ()
824
823
.optionalStart ().appendZoneOrOffsetId ().optionalEnd ()
825
824
.optionalStart ().appendOffset ("+HHmm" , "Z" ).optionalEnd ()
@@ -840,7 +839,7 @@ public class DateFormatters {
840
839
.appendValue (MINUTE_OF_HOUR , 1 , 2 , SignStyle .NOT_NEGATIVE )
841
840
.appendLiteral (':' )
842
841
.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 )
844
843
.toFormatter (Locale .ROOT );
845
844
846
845
private static final DateTimeFormatter ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder ()
@@ -875,7 +874,7 @@ public class DateFormatters {
875
874
876
875
private static final DateTimeFormatter TIME_PREFIX = new DateTimeFormatterBuilder ()
877
876
.append (TIME_NO_MILLIS_FORMATTER )
878
- .appendFraction (MILLI_OF_SECOND , 1 , 3 , true )
877
+ .appendFraction (NANO_OF_SECOND , 1 , 3 , true )
879
878
.toFormatter (Locale .ROOT );
880
879
881
880
private static final DateTimeFormatter WEEK_DATE_FORMATTER = new DateTimeFormatterBuilder ()
@@ -963,7 +962,7 @@ public class DateFormatters {
963
962
.optionalStart ()
964
963
.appendLiteral (':' )
965
964
.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 )
967
966
.optionalEnd ()
968
967
.toFormatter (Locale .ROOT );
969
968
@@ -1068,7 +1067,7 @@ public class DateFormatters {
1068
1067
.optionalStart ()
1069
1068
.appendLiteral (':' )
1070
1069
.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 )
1072
1071
.optionalEnd ()
1073
1072
.toFormatter (Locale .ROOT );
1074
1073
@@ -1453,18 +1452,21 @@ static JavaDateFormatter merge(String pattern, List<DateFormatter> formatters) {
1453
1452
assert formatters .size () > 0 ;
1454
1453
1455
1454
List <DateTimeFormatter > dateTimeFormatters = new ArrayList <>(formatters .size ());
1455
+ DateTimeFormatterBuilder roundupBuilder = new DateTimeFormatterBuilder ();
1456
1456
DateTimeFormatter printer = null ;
1457
1457
for (DateFormatter formatter : formatters ) {
1458
1458
assert formatter instanceof JavaDateFormatter ;
1459
1459
JavaDateFormatter javaDateFormatter = (JavaDateFormatter ) formatter ;
1460
- DateTimeFormatter dateTimeFormatter = javaDateFormatter .getParser ();
1461
1460
if (printer == null ) {
1462
1461
printer = javaDateFormatter .getPrinter ();
1463
1462
}
1464
- dateTimeFormatters .add (dateTimeFormatter );
1463
+ dateTimeFormatters .add (javaDateFormatter .getParser ());
1464
+ roundupBuilder .appendOptional (javaDateFormatter .getRoundupParser ());
1465
1465
}
1466
+ DateTimeFormatter roundUpParser = roundupBuilder .toFormatter (Locale .ROOT );
1466
1467
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 ]));
1468
1470
}
1469
1471
1470
1472
private static final ZonedDateTime EPOCH_ZONED_DATE_TIME = Instant .EPOCH .atZone (ZoneOffset .UTC );
0 commit comments