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

Duration returns a formatted string. #1132

Open
c0dezer019 opened this issue Feb 6, 2022 · 1 comment
Open

Duration returns a formatted string. #1132

c0dezer019 opened this issue Feb 6, 2022 · 1 comment

Comments

@c0dezer019
Copy link

c0dezer019 commented Feb 6, 2022

Is your feature request related to a problem? Please describe.
The problem I face in my current project is developing a dynamic string such as 10 months, 24 days, 1 minute, and 25 seconds. that is grammatically correct and ignores values that are 0 (or adds if preferred to be more verbose about 0 values). The sentence should also be grammatically correct, swapping between singular and plural as needed.

Describe the solution you'd like
I have a two-fold solution.

Duration and diff practically return the same data. So I propose consolidating the functionality of .diff() into Duration. Instead of doing end.diff(start) you could do Duration(start, end).toDuration() which would perform the difference calculation and return the example I provided above. Coupled with current functionality, Duration.fromObject({}).toDuration() would return the same thing.

Describe alternatives you've considered

Additional context
Add any other context or screenshots about the feature request here.

@icambron
Copy link
Member

ignores values that are 0 (or adds if preferred to be more verbose about 0 values)

I think #1134 captures this well.

Duration and diff practically return the same data. So I propose consolidating the functionality of .diff() into Duration.

This is already true; diff() is a method on DateTime that returns a Duration object. So I'm not really sure what's being proposed here?

Instead of doing end.diff(start) you could do Duration(start, end).toDuration() which would perform the difference calculation and return the example I provided above

You can already do this with Interval: Interval.fromDateTimes(start, end).toDuration() though it is semantically equivalent to end.diff(start)

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

No branches or pull requests

2 participants