razorcat
razorcat

Reputation: 73

Dates in Safari appear off by one using Intl.DateTimeFormat with en-US locale

It looks like Safari's implementation of Int.DateTimeFormat assumes that the second Sunday in March will ALWAYS be the DST time cutoff which is not correct as prior to 2007 it was the first Sunday in April. It also appears that this affects the other end as well when DST ends. PS: This code is being run in Indiana, USA which is in the eastern time zone (GMT-4)

More specifically...

Here's a little JSBin that outlines the exact dates where this becomes an issue (note it all works correctly on every browser but safari) https://jsbin.com/mayadehowu/edit?js,output

var formatter = new Intl.DateTimeFormat('en');
var date = new Date('6/2/2005');
console.log(formatter.format(date)); // => outputs "6/1/2005"

I dug in further and it may be due to this change in the ECMA specifications.

Has anyone else encountered this problem? If so what were your solutions to work around this? I need a fix, but I am skeptical to patch over a safari-specific bug by adding an hour in specific cases because if Safari fixes this then our logic will be broken again.

Upvotes: 3

Views: 2396

Answers (1)

razorcat
razorcat

Reputation: 73

This was finally fixed in Safari 14.1 per @NathanQ's comment

Upvotes: 0

Related Questions