Skip to content

Commit 83f7996

Browse files
committed
Polishing
1 parent 0544dfe commit 83f7996

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -29,7 +29,7 @@
2929
/**
3030
* Configures basic date formatting for use with Spring, primarily for
3131
* {@link org.springframework.format.annotation.DateTimeFormat} declarations.
32-
* Applies to fields of type {@link Date}, {@link Calendar} and {@code long}.
32+
* Applies to fields of type {@link Date}, {@link Calendar}, and {@code long}.
3333
*
3434
* <p>Designed for direct instantiation but also exposes the static
3535
* {@link #addDateConverters(ConverterRegistry)} utility method for

spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -76,8 +76,8 @@ public DateTimeFormatterRegistrar() {
7676

7777
/**
7878
* Set whether standard ISO formatting should be applied to all date/time types.
79-
* Default is "false" (no).
80-
* <p>If set to "true", the "dateStyle", "timeStyle" and "dateTimeStyle"
79+
* <p>Default is "false" (no).
80+
* <p>If set to "true", the "dateStyle", "timeStyle", and "dateTimeStyle"
8181
* properties are effectively ignored.
8282
*/
8383
public void setUseIsoFormat(boolean useIsoFormat) {
@@ -88,23 +88,23 @@ public void setUseIsoFormat(boolean useIsoFormat) {
8888

8989
/**
9090
* Set the default format style of {@link java.time.LocalDate} objects.
91-
* Default is {@link java.time.format.FormatStyle#SHORT}.
91+
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
9292
*/
9393
public void setDateStyle(FormatStyle dateStyle) {
9494
this.factories.get(Type.DATE).setDateStyle(dateStyle);
9595
}
9696

9797
/**
9898
* Set the default format style of {@link java.time.LocalTime} objects.
99-
* Default is {@link java.time.format.FormatStyle#SHORT}.
99+
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
100100
*/
101101
public void setTimeStyle(FormatStyle timeStyle) {
102102
this.factories.get(Type.TIME).setTimeStyle(timeStyle);
103103
}
104104

105105
/**
106106
* Set the default format style of {@link java.time.LocalDateTime} objects.
107-
* Default is {@link java.time.format.FormatStyle#SHORT}.
107+
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
108108
*/
109109
public void setDateTimeStyle(FormatStyle dateTimeStyle) {
110110
this.factories.get(Type.DATE_TIME).setDateTimeStyle(dateTimeStyle);
@@ -138,7 +138,7 @@ public void setTimeFormatter(DateTimeFormatter formatter) {
138138

139139
/**
140140
* Set the formatter that will be used for objects representing date and time values.
141-
* <p>This formatter will be used for {@link LocalDateTime}, {@link ZonedDateTime}
141+
* <p>This formatter will be used for {@link LocalDateTime}, {@link ZonedDateTime},
142142
* and {@link OffsetDateTime} types. When specified, the
143143
* {@link #setDateTimeStyle dateTimeStyle} and
144144
* {@link #setUseIsoFormat useIsoFormat} properties will be ignored.

spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterUtils.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 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.
@@ -29,10 +29,18 @@
2929
*/
3030
abstract class DateTimeFormatterUtils {
3131

32+
/**
33+
* Create a {@link DateTimeFormatter} for the supplied pattern, configured with
34+
* {@linkplain ResolverStyle#STRICT strict} resolution.
35+
* <p>Note that the strict resolution does not affect the parsing.
36+
* @param pattern the pattern to use
37+
* @return a new {@code DateTimeFormatter}
38+
* @see ResolverStyle#STRICT
39+
*/
3240
static DateTimeFormatter createStrictDateTimeFormatter(String pattern) {
33-
// Using strict parsing to align with Joda-Time and standard DateFormat behavior:
41+
// Using strict resolution to align with Joda-Time and standard DateFormat behavior:
3442
// otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected.
35-
// However, with strict parsing, a year digit needs to be specified as 'u'...
43+
// However, with strict resolution, a year digit needs to be specified as 'u'...
3644
String patternToUse = StringUtils.replace(pattern, "yy", "uu");
3745
return DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT);
3846
}

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ class DateFormattingTests {
6161

6262
@BeforeEach
6363
void setup() {
64-
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
65-
setup(registrar);
64+
DefaultConversionService.addDefaultConverters(conversionService);
65+
setup(new DateFormatterRegistrar());
6666
}
6767

6868
private void setup(DateFormatterRegistrar registrar) {
69-
DefaultConversionService.addDefaultConverters(conversionService);
7069
registrar.registerFormatters(conversionService);
7170

7271
SimpleDateBean bean = new SimpleDateBean();
@@ -172,7 +171,7 @@ void testBindDateAnnotatedWithError() {
172171
@Test
173172
@Disabled
174173
void testBindDateAnnotatedWithFallbackError() {
175-
// TODO This currently passes because of the Date(String) constructor fallback is used
174+
// TODO This currently passes because the Date(String) constructor fallback is used
176175
MutablePropertyValues propertyValues = new MutablePropertyValues();
177176
propertyValues.add("styleDate", "Oct 031, 2009");
178177
binder.bind(propertyValues);
@@ -181,7 +180,7 @@ void testBindDateAnnotatedWithFallbackError() {
181180
}
182181

183182
@Test
184-
void testBindDateAnnotatedPattern() {
183+
void testBindDateTimePatternAnnotated() {
185184
MutablePropertyValues propertyValues = new MutablePropertyValues();
186185
propertyValues.add("patternDate", "10/31/09 1:05");
187186
binder.bind(propertyValues);
@@ -190,7 +189,7 @@ void testBindDateAnnotatedPattern() {
190189
}
191190

192191
@Test
193-
void testBindDateAnnotatedPatternWithGlobalFormat() {
192+
void testBindDateTimePatternAnnotatedWithGlobalFormat() {
194193
DateFormatterRegistrar registrar = new DateFormatterRegistrar();
195194
DateFormatter dateFormatter = new DateFormatter();
196195
dateFormatter.setIso(ISO.DATE_TIME);
@@ -205,7 +204,7 @@ void testBindDateAnnotatedPatternWithGlobalFormat() {
205204
}
206205

207206
@Test
208-
void testBindDateTimeOverflow() {
207+
void testBindDateTimePatternAnnotatedWithOverflow() {
209208
MutablePropertyValues propertyValues = new MutablePropertyValues();
210209
propertyValues.add("patternDate", "02/29/09 12:00 PM");
211210
binder.bind(propertyValues);

spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryBeanTests.java

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525

26-
27-
28-
29-
3026
/**
3127
* @author Phillip Webb
3228
* @author Sam Brannen

0 commit comments

Comments
 (0)