Skip to content

Allow easy activation of ISO-by-default date and time binding for Spring MVC #20579

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

Closed
odrotbohm opened this issue Mar 19, 2020 · 1 comment
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@odrotbohm
Copy link
Member

odrotbohm commented Mar 19, 2020

As indicated in this ticket, it's a bit cumbersome (though doable) to make Spring MVC properly bind the ISO dates and times created through HTML input elements of type date or time. A custom WebMvcConfigurer can be used to enable this by default:

@Bean
WebMvcConfigurer isoDatesByDefault() {
  return new WebMvcConfigurer() {
    public void addFormatters(FormatterRegistry registry) {
      DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
      registrar.setUseIsoFormat(true);
      registrar.registerFormatters(registry);
    }
  }
}

As it's very likely to be what users expect to work by default, it would be cool if this could be enabled via a property. I guess for backwards compatibility reasons it should stay deactivated by default.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2020
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 15, 2020
@philwebb philwebb added this to the 2.3.x milestone Apr 15, 2020
@wilkinsona
Copy link
Member

Joining some dots. This was requested in #18511 alongside properties for configuring the time and date-time format. It was closed as being superseded by a pull request. The pull request doesn't add the ISO support, just the properties for time and date-time format.

There are two approaches that could be taken here:

  1. Add a separate property for enabling ISO formatting. This would then result in the properties for the date, time, and date-time formats being ignored.
  2. Allow a special value of iso (case-insensitive) to be used when configuring the date, time, and date-time formats.

There are pros and cons for each of these. The pro for 1 is that it gives you a single property to enable ISO formatting. The con is that it can lead to other properties being ignored. The pro for 2 is that no properties will be ignored as a result of another property being set. The con is that you need to set three properties to enable ISO formatting.

2 is our preferred option.

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

No branches or pull requests

4 participants