Open bjuppa opened 1 year ago
These are just my quick thoughts jotted down! ☝️
Please contribute your ideas about balancing/rescaling/normalizing!
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
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 millisecondsis(other: Duration) => boolean
equality checkround() => Duration
rescale(shape: SloppyDuration) => Duration
add(duration: Duration): Duration
subtract(duration: Duration): Duration
asHours()
,asDays()
, etcUse
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!