Skip to content

Period conversion does not support a ChronoUnit of WEEKS but supports weeks in ISO-8601 (e.g. P2W) and simple (e.g. 2w) formats #22225

Closed

Description

@AlexFalappa

It may be worth adding to the documentation (chapter 2.8.8) that ChronoUnit.WEEKS is not supported in @PeriodUnit annotation to specify how to interpret unqualified integer values for Period configuration properties fields.

Specifying weeks fails with a root cause of:

...
Caused by: java.lang.IllegalArgumentException: '2' is not a valid simple period
	at org.springframework.boot.convert.PeriodStyle$1.parse(PeriodStyle.java:59) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.StringToPeriodConverter.convert(StringToPeriodConverter.java:65) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.StringToPeriodConverter.convert(StringToPeriodConverter.java:50) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41) ~[spring-core-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	... 57 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported unit Weeks
	at org.springframework.boot.convert.PeriodStyle$Unit.fromChronoUnit(PeriodStyle.java:273) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.PeriodStyle$1.parse(PeriodStyle.java:47) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	... 60 common frames omitted

Activity

  1. added
    status: waiting-for-triage
    on Jul 5, 2020
  2. wilkinsona commented on Jul 6, 2020

    @wilkinsona
    Member

    Thanks, @AlexFalappa. This looks like a bug to me. We support weeks with the ISO-8601 and simple formats. Unless I've missed something, there's no reason why they're not also supported when specify an int and a ChronoUnit of weeks.

    Period has no accessor for weeks but I don't believe we need one. For String -> Period conversion we don't access any of the components of the period. For Period -> String conversion we only need years, months, and days. I think we can safely add WEEKS to PeriodStyle.Unit that supports parsing but not printing.

  3. added
    type: bug
    and removed
    status: waiting-for-triage
    on Jul 6, 2020
  4. changed the title [-]Document supported ChronoUnit values for @PeriodUnit annotation[/-] [+]Period conversion does not support a ChronoUnit of `WEEKS` but supports weeks in ISO-8601 (e.g. P2W) and simple (e.g. 2w) formats[/+] on Jul 6, 2020
  5. changed the title [-]Period conversion does not support a ChronoUnit of `WEEKS` but supports weeks in ISO-8601 (e.g. P2W) and simple (e.g. 2w) formats[/-] [+]Period conversion does not support a ChronoUnit of WEEKS but supports weeks in ISO-8601 (e.g. P2W) and simple (e.g. 2w) formats[/+] on Jul 6, 2020
  6. added this to the milestone on Jul 6, 2020
  7. self-assigned this
    on Jul 6, 2020
  8. modified the milestones: , 2.3.2 on Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions