jsmreese / moment-duration-format

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

`toLocaleString` is not fully implemented in many environments #90

Closed jsmreese closed 6 years ago

jsmreese commented 6 years ago

Number#toLocaleString is not fully implemented in many environments, including IE10, IE11, Android, and others.

The moment duration format plugin should test the functionality of Number#toLocaleString before using it. And should employ a fallback version that implements those options used by the plugin.

See #68 and #69.

jsmreese commented 6 years ago

@mikeevstropov can you take a look at https://github.com/andyearnshaw/Intl.js I think that if you were to add this lib to your project, everything might just work.

I'll check it out myself, but it might be a couple weeks before I'm able to.

jsmreese commented 6 years ago

@darkbluesun @mikeevstropov I've pushed a version of the plugin with a working fallback format function to the polyfill branch.

Using BrowserStack, all tests pass on IE 9 and 10, and Android 2.3, 4.4, and 6 in various browsers. Well, all tests except for two floating-point rounding errors when using the fallback format function (#93).

Please give this version a shot if you have a chance. I need to updated the documentation (may be a few days) before I publish the new version.

christheyounger commented 6 years ago

This fixes the behaviour in my app in IE10 👍

jsmreese commented 6 years ago

Thank you for testing @darkbluesun!

Pushed a new version to the polyfill branch that uses string-based rounding to fix #93 and #94 when using the fallback format function.

Ironically, IE11, Edge, and Windows Phone don't need to use the fallback format function, but they show those same floating point rounding errors when using toLocaleString. Gotta love JavaScript sometimes!

I still need to update the docs before publishing the new version.

jsmreese commented 6 years ago

Just published version 2.2.0 with the fallback function.

christheyounger commented 6 years ago

Thanks! 😄