Closed valentine-dev closed 2 years ago
Not sure it is a bug.
From the ISO-8601 spec (emphasize is mine)
The capital letters P, Y, M, W, D, T, H, M, and S are designators for each of the date and time elements and are not replaced
It explicitly mentions capital letters. So one could argue that Spring (Boot) might adhere to strictly to the standard as opposed the java.time.Duration
class?
Given that we say we use the format that is used by java.time.Duration, I think it's reasonable to expect the detect and detectAndParse methods to align with Duration's own parsing.
I'm not sure that we need to go as far as using the same pattern as Duration does. Our simpler pattern used case-insensitively may be enough for our detection needs.
Given that we say we use the format that is used by java.time.Duration, I think it's reasonable to expect the detect and detectAndParse methods to align with Duration's own parsing.
I'm not sure that we need to go as far as using the same pattern as Duration does. Our simpler pattern used case-insensitively may be enough for our detection needs.
Thanks for the feedback!
Add a lower-case P in the current simpler pattern may be enough - update "^[+-]?P.*$"
to be "^[+-]?[pP].*$"
.
I would be happy to fix this small bug if needed. @wilkinsona
PR created at https://github.com/spring-projects/spring-boot/pull/32223 to fix this bug - please have a review.
Closing in favor of PR #32223. Thanks @valentine-dev!
Bug Report
Environment
Version of Spring Boot
2.7.3
Version of Java
11
Expected (what is in the Reference Documentation)
from https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.conversion.durations
Actual Behavior
Some format used by java.time.Duration is not working in Spring Boot app, like "pt25.234s" demonstrated in the example application at https://github.com/valentine-dev/spring-boot-duration-style-iso8601
Suggestion Solution
Pattern.CASE_INSENSITIVE
as the second argument to thePattern.compile
method at Line 87 of DurationStyle.java"([-+]?)P(?:([-+]?[0-9]+)D)?" +
"(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?"