iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
46.99k stars 2.3k forks source link

Converting to ISO 8601 standard duration format #519

Closed suyalcinkaya closed 5 years ago

suyalcinkaya commented 5 years ago

Hi 👋🏼,

First of all, thank you for this great library :)

I couldn't find a way to convert the minutes or hours to ISO 8601 duration format. For example:

With moment.js I can do;

moment.duration(30, 'minutes').toISOString();
// output: PT30M

moment.duration(70, 'minutes').toISOString();
// output: PT1H10M

Couldn't find a way to do the same thing in dayjs.

Any suggestions?

ghost commented 5 years ago

Seems Duplicate of #414 ?

Or, more detail please?

iamkun commented 5 years ago

Maybe we need a dayjs. duration plugin?

suyalcinkaya commented 5 years ago

@xxyuk Well, that's all actually. Couldn't find a way to convert 30 minutes to PT30M.

@iamkun I think we need one.

mariomc commented 5 years ago

We had the same issue and ended up using ISO8601-duration (tested, pretty small, no dependencies) for that format parse and calculations.

suyalcinkaya commented 5 years ago

@mariomc Thanks mate. But it looks like it does the opposite thing for what I need.

iamkun commented 5 years ago

564 todo: Duration plugin