JakeChampion/polyfill-library

Intl: Formatting invalid date throws exception

Cellule opened this issue · 1 comments

Bug Report

What

Exception is being thrown when formatting invalid dates where native browser simply returns string "Invalid Date"

Details

This probably happens to more date format, but my particular scenario is with toLocaleDateString
In native browser implementation it has the following behavior

new Date("asd").toLocaleDateString() // Returns 'Invalid Date'

But on polyfilled browser, it throws new RangeError("invalid time");
I pinpointed to this bit of code by reviewing the polyfill
https://github.com/Financial-Times/polyfill-service/blob/291937c29371190c4e438971218d0676b0cb92d6/fastly/c-at-e/polyfill-libraries/polyfill-library-3.111.0/polyfills/__dist/Intl.DateTimeFormat/raw.js#L1006-L1015

I haven't been able to reproduce locally, but it seems to happen to some of our customers on Safari 14.0.3

We are using this configuration of for polyfill

<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?version=3.111.0&features=Intl%2Cdefault%2Ces2015%2Ces2016%2Ces2017%2Ces2018%2Ces2019%2Ces2020%2Ces2021%2Ces2022%2Ces5%2Ces6%2Ces7"></script>

This is already fixed in version 4.4.0 of the library 👍 #1186

polyfill.io is not using the v4.x.x versions of polyfill-library yet as it requires a bigger investment by me to update it whilst still supporting the 3.x.x versions (v4 removed IE 8 support)