Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grails-doc/src/en/ref/Tags - GSP/formatDate.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Formats `java.util.Date`, `java.time.LocalDate`, and `java.time.LocalDateTime` i

Attributes

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

* `date` (required) - The date object to format. It could be the instance of `java.util.Date`, `java.time.LocalDate`, `java.time.LocalDateTime`.
* `format` (optional) - The formatting pattern to use for the date, see {javase}java.base/java/text/SimpleDateFormat.html[SimpleDateFormat]
* `formatName` (optional) - Look up `format` from the default MessageSource / ResourceBundle (i18n/*.properties file) with this key. If `format` and `formatName` are empty, `format` is looked up with '`default.date.format`' key. Defaults to 'yyyy-MM-dd HH:mm:ss z' if the key not specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ class DefaultDateHelperSpec extends Specification {
null | '8:00 AM'
}

@PendingFeature
@Requires({ !Jvm.current.isJava17() })
@Requires({ Jvm.current.isJava20Compatible() })
@Unroll
void "Java 21+ - Full getTimeFormat for style #style returns #expected"(String style, String expected) {
void "Java 20+ - getTimeFormat for style #style returns #expected"(String style, String expected) {
given:
DateTimeFormatter format

Expand All @@ -111,8 +110,10 @@ class DefaultDateHelperSpec extends Specification {
format.format(localTime) == expected

where:
style | expected
'FULL' | '8:00:00 AM UTC'
style | expected
'LONG' | '8:00:00 AM UTC'
'MEDIUM' | '8:00:00 AM'
null | '8:00 AM'
}

@Requires({ Jvm.current.isJava17() })
Expand All @@ -133,6 +134,24 @@ class DefaultDateHelperSpec extends Specification {
'FULL' | '8:00:00 AM Coordinated Universal Time'
}

@Requires({ Jvm.current.isJava20Compatible() })
@Unroll
void "Java 20+ - Full getTimeFormat for style #style returns #expected"(String style, String expected) {
given:
DateTimeFormatter format

when:
format = helper.getTimeFormat(style, ZoneId.of('UTC'), Locale.ENGLISH)

then:
format.zone == ZoneId.of('UTC')
format.format(localTime) == expected

where:
style | expected
'FULL' | '8:00:00 AM Coordinated Universal Time'
}

@Requires({ jvm.isJava8() })
@Unroll("for getDateTimeFormat(#dateStyle, #timeStyle) => #expected")
void "Java 8 - test getDateTimeFormat"(String dateStyle, String timeStyle, String expected) {
Expand Down Expand Up @@ -175,6 +194,27 @@ class DefaultDateHelperSpec extends Specification {
null | null | '1/5/41, 8:00 AM'
}

@Requires({ Jvm.current.isJava20Compatible() })
@Unroll("for getDateTimeFormat(#dateStyle, #timeStyle) => #expected")
void "Java 20+ - test getDateTimeFormat"(String dateStyle, String timeStyle, String expected) {
given:
DateTimeFormatter format

when:
format = helper.getDateTimeFormat(dateStyle, timeStyle, ZoneId.of('UTC'), Locale.ENGLISH)

then:
format.zone == ZoneId.of('UTC')
format.format(LocalDateTime.of(localDate, localTime)) == expected

where:
dateStyle | timeStyle | expected
'FULL' | 'FULL' | 'Sunday, January 5, 1941, 8:00:00 AM Coordinated Universal Time'
'LONG' | 'LONG' | 'January 5, 1941, 8:00:00 AM UTC'
'MEDIUM' | 'MEDIUM' | 'Jan 5, 1941, 8:00:00 AM'
null | null | '1/5/41, 8:00 AM'
}

void "test supportsDatePickers"() {
expect:
helper.supportsDatePicker(Date)
Expand Down
Loading