ISO8601-duration icon indicating copy to clipboard operation
ISO8601-duration copied to clipboard

Add toString method

Open jsakas opened this issue 2 years ago • 5 comments

I think it would be useful to have a method similar to toSeconds, but for converting a Duration object to a ISO8601 duration string.

For example:

toString({
  "weeks": 0,
  "years": 3,
  "months": 6,
  "days": 4,
  "hours": 12,
  "minutes": 30,
  "seconds": 5
})

// P3Y6M4DT12H30M5S

jsakas avatar Apr 23 '23 15:04 jsakas

I don't see why not 😊 Are you willing to create a PR?

tolu avatar Apr 27 '23 09:04 tolu

LMAO I came here to use this lib to parse durations because https://github.com/date-fns/date-fns/issues/3150 and now I see that this lib does not format durations :D

mgohin avatar Dec 11 '23 11:12 mgohin

thats correct and I don't think it fit's the purpose of this module either, unfortunately.

I'd rather look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat for formatting (or a polyfill) since it's something that's coming to the platform 👍

tolu avatar Dec 11 '23 13:12 tolu

It would be nice for now, because it's not browser/node native, to be able to perform parse/format with one lib. But it's ok for us, we use both your lib and date-fns, so for that, thank you ❤️

mgohin avatar Dec 11 '23 13:12 mgohin