Dayjs: Feature request: Formatting duration in multiple time units

Created on 9 May 2020  路  7Comments  路  Source: iamkun/dayjs

Describe the bug
Formatting duration via .humanize() could be also achieved with multiple time units. e.g.

moment.duration({ s: 100 }).humanize({ s: true }) // '100 seconds'
moment.duration({ s: 100 }).humanize({ m: true }) // '1 minute'
moment.duration({ s: 100 }).humanize({ m: true, s: true }) // '1 minute 40 seconds'
moment.duration({ s: 100 }).humanize({ ms: true }) // '10000 milliseconds'
enhancement

Most helpful comment

Would also be awesome if we could display it with in zero padded units, such as:

dayjs.duration({ s: 12345678 }).format('HH:mm:ss')

Is there anything like that?

All 7 comments

Would also be awesome if we could display it with in zero padded units, such as:

dayjs.duration({ s: 12345678 }).format('HH:mm:ss')

Is there anything like that?

@glennreyes something like this? https://github.com/iamkun/dayjs/issues/641#issuecomment-643924034

@guanzo looks like a sweet solution.

@iamkun is that how you're supposed to do it tho? I sort of tried random combinations of dayjs methods until it worked lmao

@guanzo Don't have a plan yet.
Still, it's a very nice solution and of great inspiration to me.

@iamkun I edited my linked comment. My "solution" only works for durations < 24 hours, and trying it with vanilla moment yields the same issue. I linked a reputable community plugin that does it correctly, dayjs may need something similar. https://github.com/jsmreese/moment-duration-format

This sort-of can be done with duration.$d but I don't think users should access it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sunrise1970 picture Sunrise1970  路  4Comments

g1eny0ung picture g1eny0ung  路  4Comments

paraself picture paraself  路  3Comments

vaquel picture vaquel  路  3Comments

fundon picture fundon  路  5Comments