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 an object type and utils for durations #75

Open
bjuppa opened this issue Aug 10, 2023 · 2 comments
Open

Add an object type and utils for durations #75

bjuppa opened this issue Aug 10, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bjuppa
Copy link
Owner

bjuppa commented Aug 10, 2023

Create factory function Duration for duration objects (time-period, span, stretch), like 3 days, 4 hours, 25 minutes.

Some resolution units to consider, each can be negative, at least one needs to be given:

Time-level:

  • milliseconds
  • seconds
  • minutes
  • hours

Days-level:

  • days
  • weeks

Months-level:

  • months
  • quarters
  • years
  • decades
  • centuries
  • millennia

Upon object creation, normalize / balance to the largest given unit within each level.

Properties and methods:

  • iso
  • toString() => iso
  • toJson() => iso
  • valueOf() => number tally milliseconds
  • is(other: Duration) => boolean equality check
  • round() => Duration
  • rescale(shape: SloppyDuration) => Duration
  • add(duration: Duration): Duration
  • subtract(duration: Duration): Duration
  • asHours(), asDays(), etc

Use Intl number format to localise strings using units. See how Luxon does this!
Check Temporal for balancing https://tc39.es/proposal-temporal/docs/balancing.html and compare that to Luxon's round, rescale & shift!

@bjuppa
Copy link
Owner Author

bjuppa commented Aug 10, 2023

These are just my quick thoughts jotted down! ☝️

Please contribute your ideas about balancing/rescaling/normalizing!

@bjuppa bjuppa added enhancement New feature or request help wanted Extra attention is needed labels Aug 10, 2023
@bjuppa
Copy link
Owner Author

bjuppa commented Mar 20, 2024

For creating human readable strings of a duration, we should look into Intl RelativeTimeFormat

https://www.raymondcamden.com/2024/03/07/using-intlrelativetimeformat-for-localized-relative-timings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant