tolu / ISO8601-duration

Node/Js-module for parsing and making sense of ISO8601-durations
92 stars 10 forks source link

Feature request: fromSeconds #31

Closed mik-jozef closed 1 year ago

mik-jozef commented 1 year ago

Hi!

You have a function toSeconds, I'd like to propose an inverse function:

fromSeconds: (seconds: number, startDate?: Date) => Duration
tolu commented 1 year ago

Hi @mik-jozef 👋

I can see how that could might usable in some situations (mostly constructing ISO-8601-durations) but I try to refrain from adding functionality to this package that is outside of the scope and unfortunately the scope here is mainly parsing from ISO-8601.

Adding the reverse, I'm afraid, would incur a lot of complexity to this project that most users do not need, mainly figuring out how to smartly bin the seconds into years, months, weeks, days and so on... Especially if you allow for a variable start date. And in all honesty - a finite amount of seconds is already a duration by any definition 😊

I suggest you instead check out the upcoming standard (there is already a working polyfill available) that can do exactly what you want: https://tc39.es/proposal-temporal/docs/duration.html#from