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

[SOLVED] moment.duration.format to show 12 sec in the format 00:12 (mm:ss) #68

Closed
fntgnn opened this issue Mar 16, 2017 · 6 comments
Closed

Comments

@fntgnn
Copy link

fntgnn commented Mar 16, 2017

Hi.
How can I use the format to show for example 12 seconds in the format 00:12 and not only 12?
I used format('mm:ss', { forceLength: true } but it does not work.

Thank you.
Giovanni.

@jsmreese
Copy link
Owner

jsmreese commented Mar 16, 2017 via email

@fntgnn
Copy link
Author

fntgnn commented Mar 16, 2017

Thank you very much!

@fntgnn fntgnn changed the title moment.duration.format to show 12 sec in the format 00:12 (mm:ss) [SOLVED] moment.duration.format to show 12 sec in the format 00:12 (mm:ss) Mar 16, 2017
@mikeevstropov
Copy link

No. Is not working as expected

import moment from 'moment'
import momentDurationPlugin from 'moment-duration-format'
momentDurationPlugin(moment)

moment.duration(12, "seconds").format('mm:ss', { trim: false })
// 0:12
moment.duration(12, "seconds").format('mm:ss', { trim: false })
// 0:1
moment.duration(1200, "seconds").format('hh:mm', { trim: false })
// 0:20
"moment": "2.19.4",
"moment-duration-format": "2.1.0",

@jsmreese
Copy link
Owner

@mikeevstropov what environment are you using?

A quick check in Chrome and I see:

moment.duration(12, "seconds").format('mm:ss', { trim: false })
// "00:12"
moment.duration(12, "seconds").format('mm:ss', { trim: false })
// "00:12"
moment.duration(1200, "seconds").format('hh:mm', { trim: false })
// "00:20"

The output padding in version 2 comes from toLocaleString... are you in an environment with a borked version of toLocaleString?

@mikeevstropov
Copy link

@jsmreese Hi! Thank you for fast reply =)

React Native (android)

"react": "16.0.0",
"react-native": "0.51.0",

@jsmreese
Copy link
Owner

That explains it. As I'm learning, there are lots of environments where you can use moment that don't provide a fully baked toLocaleString.

I'll see what I can do about getting a fallback implementation of toLocaleString into the plugin.

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

No branches or pull requests

3 participants