Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Formatting duration in multiple time units #897

Open
Alanscut opened this issue May 9, 2020 · 9 comments
Open

Feature request: Formatting duration in multiple time units #897

Alanscut opened this issue May 9, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@Alanscut
Copy link

Alanscut commented May 9, 2020

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'
@glennreyes
Copy link

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?

@guanzo
Copy link

guanzo commented Jun 15, 2020

@glennreyes something like this? #641 (comment)

@iamkun
Copy link
Owner

iamkun commented Jun 15, 2020

@guanzo looks like a sweet solution.

@guanzo
Copy link

guanzo commented Jun 15, 2020

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

@iamkun
Copy link
Owner

iamkun commented Jun 15, 2020

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

@guanzo
Copy link

guanzo commented Jun 15, 2020

@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

@papaia
Copy link

papaia commented Jun 18, 2020

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

@iamkun iamkun added the enhancement New feature or request label Jul 22, 2020
@Gameghostify
Copy link

What's the status of this? Would love to have this feature as well!

@JiangWeixian
Copy link

maybe create a another plugin to support asDays return with unit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants