Skip to content

Add an object type and utils for durations #75

@bjuppa

Description

@bjuppa

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions