jsmreese / moment-duration-format

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

Can't format a moment in IE10 "Unable to get property '1' of undefined or null reference" #69

Closed christheyounger closed 7 years ago

christheyounger commented 7 years ago

Open the console, run: moment.duration(928515).format(); Safari Says: "15:29" IE10 Says: "Unable to get property '1' of undefined or null reference"

emielvanliere commented 7 years ago

Workaround: moment.duration.fn.format.defaults.decimalSeparator = ':';

jsmreese commented 7 years ago

Closing this. FIxed in 89839039b7995d6d0a05a758f356a53dd5fd5943. This issue was fixed by removing the decimalSeparator option and the defaultDecimalSeparator function that caused the issue. Decimal separators are now rendered via toLocaleString.

christheyounger commented 7 years ago

Yeah, but now when I run moment.duration(928515).format() I get "15.00:29.00" That's a hell of a format

jsmreese commented 7 years ago

You must have something changed in the default settings? With a test page that was loaded from close to the head of master on github, I see something reasonable...

moment.duration(928515).format();
//"15:29"
christheyounger commented 6 years ago

Please see this codepen: https://codepen.io/darkbluesun/pen/MrygQZ 15.00:29.00 in IE10 I'm happy for you to fork and fix it if I've done something wrong

jsmreese commented 6 years ago

@darkbluesun It looks like IE10 doesn't have full support for toLocaleString, which is used to format numbers in version 2 of the plugin.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Would a polyfill work for you? There look to be a few, but I haven't checked out what options they support. minimumIntegerDigits, minimumFractionDigits, and maximumFractionDigits are required for the basics.

jsmreese commented 6 years ago

@darkbluesun as I'm learning, there are lots of environments where you can use moment that do not provide a fully baked toLocaleString implementation. I'm going to see what I can do about getting a fallback version into the plugin.