Skip to content
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

g:formatDate doesn't fully support LocalDate #87

Closed
xpusostomos opened this issue Mar 30, 2021 · 2 comments
Closed

g:formatDate doesn't fully support LocalDate #87

xpusostomos opened this issue Mar 30, 2021 · 2 comments
Milestone

Comments

@xpusostomos
Copy link

Generally speaking, grails fully supports LocalDate as a replacement for Date. However I found a bug where it doesn't work.

<g:formatDate date="${ java.time.LocalDate.now()}"/>

Error processing GroovyPageView: [views/index.gsp:32] Error executing tag <g:formatDate>: Unsupported field: HourOfDay

Note that this does work:

<g:formatDate date="${ java.time.LocalDate.now()}" format="yyyy-MM-dd"/>

as does this:

<g:formatDate date="${ new java.util.Date()}"/>

Oh, one other thing... since g:formatDate actually seems supposed to support times as well... according to the documentation... it should really support LocalDateTime as well. The Date class needs to be consigned to the dustbin of history, and Grails domain classes seem to support LocalDate and LocalDateTime just fine, so grails is oh so close to being fully compliant. But LocalDateTime scenarios don't seem to work at all.

It would also be nice if the documentation for g:formatDate was updated to mention LocalDate
`

Task List

Put this in your GSP

<g:formatDate date="${ java.time.LocalDate.now()}"/>

crash

Expected Behaviour

Not crash.

Actual Behaviour

Error processing GroovyPageView: [views/index.gsp:32] Error executing tag <g:formatDate>: Unsupported field: HourOfDay

Environment Information

  • Grails Version: 4.0.9
  • JDK Version: 8
@puneetbehl
Copy link
Contributor

The LocalDate and LocalDateTime should be supported. The reason you see error is because LocalDate does not have any time information whereas in the message properties the default format is defined as:

default.date.format=yyyy-MM-dd HH:mm:ss z

@puneetbehl puneetbehl transferred this issue from grails/grails-core Apr 2, 2021
@puneetbehl puneetbehl added this to the 4.0.3 milestone Apr 2, 2021
@xpusostomos
Copy link
Author

Well... since 90% of usage is probably dates, rather than date/times, that's kinda broken. Not much point having a default.date.format that mostly fails. Maybe you need a default.datetime.format as a separate thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants