You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('does not interchange the day and month when the locale is not supported', function () {
// in an environment where locale "de" is not supported
const option: Options = { day: 'numeric', month: 'numeric', year: 'numeric' };
expect(Intl.DateTimeFormat.supportedLocalesOf('de')).to.eql([]);
expect(parser('de', option).parse('03.06.2023')).to.not.eql(new Date('2023-03-06'));
expect(parser('de', option).parse('03.06.2023')).to.eql(undefined);
});
The
dateTimeFormat
function depends on the requested locale being supported by the host system which isn't always the case.totallylazy.js/src/dates/format.ts
Lines 11 to 13 in 391168f
By default Intl.DateTimeFormat uses a "best fit" algorithm to match the requested locale and so if the locale is not known it returns the default:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locale_identification_and_negotiation
e.g.
Ideally, when parsing a date, I would like a way to guard against the locale being unsupported without having to do this outside of the totallylazy library. Intl does support this through the use of
Intl.DateTimeFormat.supportedLocalesOf
.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/supportedLocalesOf
e.g.
The text was updated successfully, but these errors were encountered: