Intl.js icon indicating copy to clipboard operation
Intl.js copied to clipboard

91% of formatted dates differ from native implementation

Open vectart opened this issue 9 years ago • 18 comments

Since I had faced https://github.com/andyearnshaw/Intl.js/issues/117 formatting issue, I created a simple check suite of native and polyfill implementation and it revealed that 5313 from 5831 formatted dates are different from native ones (https://jsbin.com/wekebe/edit?js,output, check Chrome dev console)

intl_results

Could be the Intl.js improved to fit at least 50% of variations?

vectart avatar Jul 14 '15 11:07 vectart

@vectart this is awesome. I will look into the details when I get a chance.

caridy avatar Jul 14 '15 12:07 caridy

Note to self: exact same results are exhibited in firefox.

caridy avatar Jul 14 '15 12:07 caridy

Whilst fixing this, it might be worth including this code as a regression test suite with an automatic fail if we don't achieve above a certain threshold. I've been wanting to write some regression tests for a while now, it didn't occur to me to check all permutations against the native implementation that's shipped with node v0.12.

V8's Intl still fails a few of DateTimeFormat tests, but I think those are more or less superficial.

andyearnshaw avatar Jul 14 '15 22:07 andyearnshaw

I do have a test suite locally that I was planning to commit. Will try to get that in soon. @jasonmit was also going to help with that.

caridy avatar Jul 14 '15 23:07 caridy

Awesome, I look forward to seeing it in action. :-)

andyearnshaw avatar Jul 15 '15 07:07 andyearnshaw

Yes, it would be great to see in test results something more meaningful than

9.2.1_1
9.2.1_3
9.2.1_4
9.2.1_8_c_ii
9.2.1_8_c_vi
9.2.2

vectart avatar Jul 15 '15 08:07 vectart

@vectart those are generated tests for every step of the algo based on the specifications, we will just add other tests to verify cldr data, and compare with native.

caridy avatar Jul 15 '15 12:07 caridy

Seems like these generated tests are absolutely useless

vectart avatar Jul 15 '15 14:07 vectart

@vectart: those tests are incredibly useful. Although they don't assume any specific locales are supported (or that we're even using CLDR), they ensure that the bare minimum of required date/time formats are supported, the correct options are resolved for formatters, tags are properly canonicalised and matched and much more.

That being said, Intl.js has sorely needed some tests to prevent locale data-based regressions for a long time.

andyearnshaw avatar Jul 15 '15 15:07 andyearnshaw

@andyearnshaw How was the bare minimum of required date/time formats defined if such basic formats doesn't work? https://github.com/andyearnshaw/Intl.js/issues/117 { month: 'long' } https://github.com/andyearnshaw/Intl.js/issues/126 { month: 'long' } https://github.com/andyearnshaw/Intl.js/issues/125 { weekday: 'long' }

I really want to use Intl.js but seems it's better to fallback to Moment.js, Globalize or other more stable date-formatting library.

vectart avatar Jul 15 '15 15:07 vectart

From the spec, section 12.2.3:

The following subsets must be available for each locale:

  • weekday, year, month, day, hour, minute, second
  • weekday, year, month, day
  • year, month, day
  • year, month
  • month, day
  • hour, minute, second
  • hour, minute

Initially, we only supported one pattern for each of those subsets, the bare minimum to meet the spec's requirements, pass the tests and cover the majority of use cases. @caridy is working on improving the date formats—have a little patience (or feel free to contribute :wink:).

andyearnshaw avatar Jul 15 '15 15:07 andyearnshaw

+1

oliviertassinari avatar Aug 21 '15 15:08 oliviertassinari

Some news about that ?

chilipote avatar Oct 26 '15 21:10 chilipote

with the v1.1.0 release, we are down to 60%, big improvements. Now I'm seeing 3505 from 5831 failed in FF and Chrome.

caridy avatar Feb 11 '16 17:02 caridy

with the v1.2.0 release, we are down to 0%, impressive. Now I'm seeing 0 from 5831 failed in FF and Chrome.

caridy avatar May 12 '16 17:05 caridy

fixed by https://github.com/andyearnshaw/Intl.js/issues/171

update: this is not fixed yet.

caridy avatar May 12 '16 17:05 caridy

Absolutely impressive! Thanks, everyone!

vectart avatar May 12 '16 18:05 vectart

@vectart something happen when attempting to test your test, I ended up copying that as part of the automation process, and I still see a bunch of differences, some of them, the polyfill is doing the right thing, while browsers take shortcut, but in general, we will have to continue this effort to close the gap. that 0% was very smelly :(, but let's keep targeting something like 20%.

caridy avatar May 13 '16 19:05 caridy