Skip to content

Commit 33d3496

Browse files
committed
Polishing
(cherry picked from commit 20dea0d)
1 parent 84a5a8a commit 33d3496

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

Diff for: spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,12 +41,12 @@ public class InstantFormatter implements Formatter<Instant> {
4141

4242
@Override
4343
public Instant parse(String text, Locale locale) throws ParseException {
44-
if (text.length() > 0 && Character.isAlphabetic(text.charAt(0))) {
44+
if (!text.isEmpty() && Character.isAlphabetic(text.charAt(0))) {
4545
// assuming RFC-1123 value a la "Tue, 3 Jun 2008 11:05:30 GMT"
4646
return Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(text));
4747
}
4848
else {
49-
// assuming UTC instant a la "2007-12-03T10:15:30.00Z"
49+
// assuming UTC instant a la "2007-12-03T10:15:30.000Z"
5050
return Instant.parse(text);
5151
}
5252
}

Diff for: spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@
5252
* @author Juergen Hoeller
5353
* @author Sam Brannen
5454
*/
55-
public class DateFormattingTests {
55+
class DateFormattingTests {
5656

5757
private final FormattingConversionService conversionService = new FormattingConversionService();
5858

Diff for: spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormattingTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -512,7 +512,7 @@ void testBindYearMonth() {
512512
}
513513

514514
@Test
515-
public void testBindYearMonthAnnotatedPattern() {
515+
void testBindYearMonthAnnotatedPattern() {
516516
MutablePropertyValues propertyValues = new MutablePropertyValues();
517517
propertyValues.add("yearMonthAnnotatedPattern", "12/2007");
518518
binder.bind(propertyValues);
@@ -531,7 +531,7 @@ void testBindMonthDay() {
531531
}
532532

533533
@Test
534-
public void testBindMonthDayAnnotatedPattern() {
534+
void testBindMonthDayAnnotatedPattern() {
535535
MutablePropertyValues propertyValues = new MutablePropertyValues();
536536
propertyValues.add("monthDayAnnotatedPattern", "1/3");
537537
binder.bind(propertyValues);
@@ -631,18 +631,18 @@ public static class DateTimeBean {
631631
@DateTimeFormat(style = "M-")
632632
private LocalDate styleLocalDate;
633633

634-
@DateTimeFormat(style = "S-", fallbackPatterns = { "yyyy-MM-dd", "yyyyMMdd", "yyyy.MM.dd" })
634+
@DateTimeFormat(style = "S-", fallbackPatterns = {"yyyy-MM-dd", "yyyyMMdd", "yyyy.MM.dd"})
635635
private LocalDate styleLocalDateWithFallbackPatterns;
636636

637-
@DateTimeFormat(pattern = "yyyy-MM-dd", fallbackPatterns = { "M/d/yy", "yyyyMMdd", "yyyy.MM.dd" })
637+
@DateTimeFormat(pattern = "yyyy-MM-dd", fallbackPatterns = {"M/d/yy", "yyyyMMdd", "yyyy.MM.dd"})
638638
private LocalDate patternLocalDateWithFallbackPatterns;
639639

640640
private LocalTime localTime;
641641

642642
@DateTimeFormat(style = "-M")
643643
private LocalTime styleLocalTime;
644644

645-
@DateTimeFormat(style = "-M", fallbackPatterns = { "HH:mm:ss", "HH:mm"})
645+
@DateTimeFormat(style = "-M", fallbackPatterns = {"HH:mm:ss", "HH:mm"})
646646
private LocalTime styleLocalTimeWithFallbackPatterns;
647647

648648
private LocalDateTime localDateTime;
@@ -662,7 +662,7 @@ public static class DateTimeBean {
662662
@DateTimeFormat(iso = ISO.DATE_TIME)
663663
private LocalDateTime isoLocalDateTime;
664664

665-
@DateTimeFormat(iso = ISO.DATE_TIME, fallbackPatterns = { "yyyy-MM-dd HH:mm:ss", "M/d/yy HH:mm"})
665+
@DateTimeFormat(iso = ISO.DATE_TIME, fallbackPatterns = {"yyyy-MM-dd HH:mm:ss", "M/d/yy HH:mm"})
666666
private LocalDateTime isoLocalDateTimeWithFallbackPatterns;
667667

668668
private Instant instant;

Diff for: spring-context/src/test/java/org/springframework/format/datetime/standard/InstantFormatterTests.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.text.ParseException;
2020
import java.time.Instant;
2121
import java.time.format.DateTimeFormatter;
22+
import java.util.Locale;
2223
import java.util.Random;
2324
import java.util.stream.Stream;
2425

@@ -49,36 +50,32 @@ class InstantFormatterTests {
4950

5051
private final InstantFormatter instantFormatter = new InstantFormatter();
5152

53+
5254
@ParameterizedTest
5355
@ArgumentsSource(ISOSerializedInstantProvider.class)
5456
void should_parse_an_ISO_formatted_string_representation_of_an_Instant(String input) throws ParseException {
5557
Instant expected = DateTimeFormatter.ISO_INSTANT.parse(input, Instant::from);
56-
57-
Instant actual = instantFormatter.parse(input, null);
58-
58+
Instant actual = instantFormatter.parse(input, Locale.US);
5959
assertThat(actual).isEqualTo(expected);
6060
}
6161

6262
@ParameterizedTest
6363
@ArgumentsSource(RFC1123SerializedInstantProvider.class)
6464
void should_parse_an_RFC1123_formatted_string_representation_of_an_Instant(String input) throws ParseException {
6565
Instant expected = DateTimeFormatter.RFC_1123_DATE_TIME.parse(input, Instant::from);
66-
67-
Instant actual = instantFormatter.parse(input, null);
68-
66+
Instant actual = instantFormatter.parse(input, Locale.US);
6967
assertThat(actual).isEqualTo(expected);
7068
}
7169

7270
@ParameterizedTest
7371
@ArgumentsSource(RandomInstantProvider.class)
7472
void should_serialize_an_Instant_using_ISO_format_and_ignoring_Locale(Instant input) {
7573
String expected = DateTimeFormatter.ISO_INSTANT.format(input);
76-
77-
String actual = instantFormatter.print(input, null);
78-
74+
String actual = instantFormatter.print(input, Locale.US);
7975
assertThat(actual).isEqualTo(expected);
8076
}
8177

78+
8279
private static class RandomInstantProvider implements ArgumentsProvider {
8380

8481
private static final long DATA_SET_SIZE = 10;
@@ -100,6 +97,7 @@ Stream<Instant> randomInstantStream(Instant min, Instant max) {
10097
}
10198
}
10299

100+
103101
private static class ISOSerializedInstantProvider extends RandomInstantProvider {
104102

105103
@Override
@@ -108,6 +106,7 @@ Stream<?> provideArguments() {
108106
}
109107
}
110108

109+
111110
private static class RFC1123SerializedInstantProvider extends RandomInstantProvider {
112111

113112
// RFC-1123 supports only 4-digit years

0 commit comments

Comments
 (0)