Closed fntgnn closed 6 years ago
In your case you'd want this:
moment.duration(12, "seconds").format('mm:ss', { trim: false });
// "00:12"
forceLength
acts on individual tokens that aren't trimmed, when the
leading token in the format string has a length of 1
. Sounds more
complicated that it is...
On Thu, Mar 16, 2017 at 11:03 AM, Giovanni Fontana <notifications@github.com
wrote:
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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jsmreese/moment-duration-format/issues/68, or mute the thread https://github.com/notifications/unsubscribe-auth/ABN2iAnlY9dobIGwCkxJNm45EHlYRmyTks5rmU8mgaJpZM4Mfbj6 .
-- John Madhavan-Reese Support Team Lead You.i TV john.madhavan-reese@youi.tv
Thank you very much!
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",
@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
?
@jsmreese Hi! Thank you for fast reply =)
React Native (android)
"react": "16.0.0",
"react-native": "0.51.0",
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.
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.