jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
968 stars 120 forks source link

Formatting hours above 24? #72

Closed dominik0711 closed 6 years ago

dominik0711 commented 7 years ago

I would like to format a summed up total working hours e.g. 29.75 to this: 29:45h.

When I use duration like this:

const dur = moment.duration(29.75, 'hours').asMilliseconds();
moment.utc(dur).format("HH:mm:ss") // 05:45:00

I'll receive 05:45:00 instead of 29:45:00

Is there a way to format duration without dropping the days? Is your plugin dealing with this correctly?

jsmreese commented 6 years ago

My plugin is handling things fine... it's just that you're not calling my plugin. You're formatting a moment object, not a moment.duration object.

Try:

dur = moment.duration(29.75, 'hours');
dur.format("hh:mm:ss")

You need to call format on a moment.duration object.

And I'd use the lowercase hh for hours. In the next week or so-ish I'm going to publish an updated version of the plugin that drops the optionally upper-cased format tokens.