Skip to content

Commit bfde33a

Browse files
committed
Document options for Date/Time parsing & formatting issues with JDK 20+
This commit updates Javadoc and the reference guide to document options for handling date/time parsing and formatting issues on JDK 20 and higher. A new "Date and Time Formatting with JDK 20 and higher" page has also been introduced in the wiki. https://github.com/spring-projects/spring-framework/wiki/Date-and-Time-Formatting-with-JDK-20-and-higher Closes gh-33151
1 parent 14b9865 commit bfde33a

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/validation/format.adoc

+26-3
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,11 @@ Kotlin::
280280

281281
A portable format annotation API exists in the `org.springframework.format.annotation`
282282
package. You can use `@NumberFormat` to format `Number` fields such as `Double` and
283-
`Long`, and `@DateTimeFormat` to format `java.util.Date`, `java.util.Calendar`, `Long`
284-
(for millisecond timestamps) as well as JSR-310 `java.time`.
283+
`Long`, and `@DateTimeFormat` to format fields such as `java.util.Date`,
284+
`java.util.Calendar`, and `Long` (for millisecond timestamps) as well as JSR-310
285+
`java.time` types.
285286

286-
The following example uses `@DateTimeFormat` to format a `java.util.Date` as an ISO Date
287+
The following example uses `@DateTimeFormat` to format a `java.util.Date` as an ISO date
287288
(yyyy-MM-dd):
288289

289290
[tabs]
@@ -309,6 +310,28 @@ Kotlin::
309310
----
310311
======
311312

313+
For further details, see the javadoc for
314+
{spring-framework-api}/format/annotation/DateTimeFormat.html[`@DateTimeFormat`] and
315+
{spring-framework-api}/format/annotation/NumberFormat.html[`@NumberFormat`].
316+
317+
[WARNING]
318+
====
319+
Style-based formatting and parsing rely on locale-sensitive patterns which may change
320+
depending on the Java runtime. Specifically, applications that rely on date, time, or
321+
number parsing and formatting may encounter incompatible changes in behavior when running
322+
on JDK 20 or higher.
323+
324+
Using an ISO standardized format or a concrete pattern that you control allows for
325+
reliable system-independent and locale-independent parsing and formatting of date, time,
326+
and number values.
327+
328+
For `@DateTimeFormat`, the use of fallback patterns can also help to address
329+
compatibility issues.
330+
331+
For further details, see the
332+
https://github.com/spring-projects/spring-framework/wiki/Date-and-Time-Formatting-with-JDK-20-and-higher[Date and Time Formatting with JDK 20 and higher]
333+
page in the Spring Framework wiki.
334+
====
312335

313336
[[format-FormatterRegistry-SPI]]
314337
== The `FormatterRegistry` SPI

Diff for: framework-docs/modules/ROOT/pages/web/webflux/config.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class WebConfig : WebFluxConfigurer {
9191
[.small]#xref:web/webmvc/mvc-config/conversion.adoc[See equivalent in the Servlet stack]#
9292

9393
By default, formatters for various number and date types are installed, along with support
94-
for customization via `@NumberFormat` and `@DateTimeFormat` on fields.
94+
for customization via `@NumberFormat` and `@DateTimeFormat` on fields and parameters.
9595

9696
To register custom formatters and converters in Java config, use the following:
9797

Diff for: framework-docs/modules/ROOT/pages/web/webmvc/mvc-config/conversion.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[.small]#xref:web/webflux/config.adoc#webflux-config-conversion[See equivalent in the Reactive stack]#
55

66
By default, formatters for various number and date types are installed, along with support
7-
for customization via `@NumberFormat` and `@DateTimeFormat` on fields.
7+
for customization via `@NumberFormat` and `@DateTimeFormat` on fields and parameters.
88

99
To register custom formatters and converters in Java config, use the following:
1010

Diff for: spring-context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@
2828
* <p>Formatting applies to parsing a date/time object from a string as well as printing a
2929
* date/time object to a string.
3030
*
31-
* <p>Supports formatting by style pattern, ISO date time pattern, or custom format pattern string.
31+
* <p>Supports formatting by style pattern, ISO date/time pattern, or custom format pattern string.
3232
* Can be applied to {@link java.util.Date}, {@link java.util.Calendar}, {@link Long} (for
3333
* millisecond timestamps) as well as JSR-310 {@code java.time} value types.
3434
*
3535
* <p>For style-based formatting, set the {@link #style} attribute to the desired style pattern code.
3636
* The first character of the code is the date style, and the second character is the time style.
3737
* Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full.
38-
* The date or time may be omitted by specifying the style character '-' &mdash; for example,
38+
* The date or time may be omitted by specifying the style character '-'. For example,
3939
* 'M-' specifies a medium format for the date with no time. The supported style pattern codes
4040
* correlate to the enum constants defined in {@link java.time.format.FormatStyle}.
4141
*
42+
* <p><strong>WARNING</strong>: Style-based formatting and parsing rely on locale-sensitive
43+
* patterns which may change depending on the Java runtime. Specifically, applications that
44+
* rely on date/time parsing and formatting may encounter incompatible changes in behavior
45+
* when running on JDK 20 or higher. Using an ISO standardized format or a concrete pattern
46+
* that you control allows for reliable system-independent and locale-independent parsing and
47+
* formatting of date/time values. The use of {@linkplain #fallbackPatterns() fallback patterns}
48+
* can also help to address compatibility issues. For further details, see the
49+
* <a href="https://github.com/spring-projects/spring-framework/wiki/Date-and-Time-Formatting-with-JDK-20-and-higher">
50+
* Date and Time Formatting with JDK 20 and higher</a> page in the Spring Framework wiki.
51+
*
4252
* <p>For ISO-based formatting, set the {@link #iso} attribute to the desired {@link ISO} format,
4353
* such as {@link ISO#DATE}.
4454
*

0 commit comments

Comments
 (0)