Skip to content

Java 20 date time formatting #14760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2025
Merged

Java 20 date time formatting #14760

merged 4 commits into from
May 21, 2025

Conversation

jamesfredley
Copy link
Contributor

@jamesfredley jamesfredley commented May 20, 2025

In Java 20+, Unicode CLDR42 was implemented which changed the space character preceding the period (AM or PM) in formatted date/time text from a standard space (" ") to a narrow non-breaking space (NNBSP: "\u202F"). Additionally, when using the LONG or FULL timeStyle with dateStyle, the date and time separator has changed from ' at ' to ', '. IE. January 5, 1941, 8:00:00 AM UTC vs. January 5, 1941 at 8:00:00 AM UTC

We already had Java 8 and 17 specific tests. For each of the Java version specific scenarios covered by prior tests, a Java 20+ test was added.

@jamesfredley jamesfredley requested a review from Copilot May 20, 2025 21:23
@jamesfredley jamesfredley self-assigned this May 20, 2025
@jamesfredley jamesfredley moved this to In Progress in Apache Grails 7.0.x May 20, 2025
@jamesfredley jamesfredley linked an issue May 20, 2025 that may be closed by this pull request
@jamesfredley jamesfredley added this to the grails:7.0.0-M4 milestone May 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds Java 20+ support for time and datetime formatting in DefaultDateHelper and documents CLDR42 changes.

  • Updates existing tests to require Java 20+ and adds new style cases for getTimeFormat.
  • Introduces a dedicated Java 20+ test for getDateTimeFormat with multiple style combinations.
  • Adds a warning to the documentation about CLDR42’s switch to narrow non-breaking spaces and separator changes.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
grails-gsp/plugin/src/test/groovy/org/grails/plugins/web/DefaultDateHelperSpec.groovy Refactored test requirements to isJava20Compatible, renamed tests, and added new style scenarios for time and datetime formatting.
grails-doc/src/en/ref/Tags - GSP/formatDate.adoc Added a warning about Java 20+ CLDR42 behavior changes in formatted date/time output.
Comments suppressed due to low confidence (3)

grails-gsp/plugin/src/test/groovy/org/grails/plugins/web/DefaultDateHelperSpec.groovy:101

  • [nitpick] The test descriptions for getTimeFormat are inconsistent: one is generic and the other includes “Full”. Consider unifying both to a standard pattern, e.g., Java 20+ - getTimeFormat for style #style returns #expected.
void "Java 20+ - getTimeFormat for style #style returns #expected"(String style, String expected) {

grails-gsp/plugin/src/test/groovy/org/grails/plugins/web/DefaultDateHelperSpec.groovy:139

  • [nitpick] This test name duplicates the first but adds “Full”; consider merging or renaming to avoid confusion and improve clarity.
void "Java 20+ - Full getTimeFormat for style #style returns #expected"(String style, String expected) {

grails-doc/src/en/ref/Tags - GSP/formatDate.adoc:60

  • [nitpick] The abbreviation “IE.” is misleading; replace it with “i.e.,” or “e.g.,” as appropriate for clarification.
WARNING: In Java 20+, https://cldr.unicode.org/downloads/cldr-42[Unicode CLDR42] was implemented which changed the space character preceding the period (AM or PM) in formatted date/time text from a standard space (" ") to a narrow non-breaking space (NNBSP: "\u202F").  Additionally, when using the LONG or FULL timeStyle with dateStyle, the date and time separator has changed from ' at ' to ', '.  IE. January 5, 1941, 8:00:00 AM UTC vs. January 5, 1941 at 8:00:00 AM UTC

@jamesfredley jamesfredley requested review from jdaugherty and matrei May 20, 2025 21:35
Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs called out in the v6 to 7 upgrade notes too

Copy link
Contributor

@matrei matrei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using a Unicode escape sequence be preferable to improve readability, rather than including a non-visible character in the comparison strings?

@jamesfredley
Copy link
Contributor Author

I have updated to tests to use \u202F instead of NNBSP. IntelliJ makes is easy to see, but it is invisible in the diff.

Also added details to Breaking changes section of v6 to 7 upgrade notes.

@jamesfredley jamesfredley merged commit 600a1d5 into 7.0.x May 21, 2025
30 checks passed
@jamesfredley jamesfredley deleted the java-20-date-time-formatting branch May 21, 2025 14:07
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache Grails 7.0.x May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Java 20+ Date Issues
3 participants