Jimbly / timezone-mock

A JavaScript library to mock the local timezone
MIT License
107 stars 35 forks source link

Error when initializing Date objects with non-ISO strings #68

Open pcnova opened 10 months ago

pcnova commented 10 months ago

Trying the following in a unit test...

timezone-mock.register('US/Pacific');
const nonIso = new Date('Fri, 05 Jan 2024 23:00:00');

...results in the following error:

Unhandled date format passed to MockDate constructor: Fri, 05 Jan 2024 23:00:00
Jimbly commented 10 months ago

That's the kind of bug this library is useful to catch =). That is a non-standard date format that may parse differently based on timezone and browser (and possibly even locale, since there's English words in there?). There are a number of non-ISO formats accepted by this library, but only those that have defined behavior in the JS spec.

If there's a compelling reason to support that format, and it can be shown that it's treated the same in all browsers in all locales, and all Node versions, then maybe it's fine though, and a PR to handle it would be accepted.