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

Add utility to parse Duration from a String #22474

Closed
mp911de opened this issue Feb 26, 2019 · 3 comments
Closed

Add utility to parse Duration from a String #22474

mp911de opened this issue Feb 26, 2019 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@mp911de
Copy link
Member

mp911de commented Feb 26, 2019

It would make sense to have a common utility to parse java.time.Duration from a CharSequence.

Examples:

  • 10ms -> 10 milliseconds
  • 10s -> 10 seconds
  • 10m -> 10 minutes
  • 10h -> 10 hours

ChronoUnits to support:

  • Nanos
  • Micros
  • Millis
  • Seconds
  • Minutes
  • Hours
  • Days

Spring Boot provides this functionality and we'd like to reuse it in Spring Data.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 26, 2019
@jhoeller jhoeller self-assigned this Feb 28, 2019
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Mar 5, 2019
@ilyavy
Copy link

ilyavy commented Jan 21, 2020

Relates to #22013

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Aug 2, 2022

Team Decision: We can do this in fallback mode, trying the built-in Duration formatting, and then falling back on alternative formats, in effect extending the built-in one. We should ensure the spec of what Boot supports already, works in the new arrangement.

@simonbasle
Copy link
Contributor

linked to #22013 and superseded by gh-30396

@simonbasle simonbasle closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2023
@jhoeller jhoeller removed this from the 6.1.x milestone May 16, 2023
bclozel pushed a commit that referenced this issue Jul 23, 2024
This commit introduces a notion of different styles for the formatting
of Duration.
The `@DurationFormat` annotation is added to ease selection of a style,
which are represented as DurationFormat.Style enum, as well as a
supported time unit represented as DurationFormat.Unit enum.

DurationFormatter has been retroffited to take such a Style,
optionally, at construction. The default is still the JDK style a.k.a.
ISO-8601.

This introduces the new SIMPLE style which uses a single number + a
short human-readable suffix. For instance "-3ms" or "2h".

This has the same semantics as the DurationStyle in Spring Boot and
is intended as a replacement for that feature, providing access to the
feature to projects that only depend on Spring Framework.

Finally, the `@Scheduled` annotation is improved by adding detection
of the style and parsing for the String versions of initial delay, fixed
delay and fixed rate.

See gh-22013
See gh-22474

Closes gh-30396
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

9 participants