'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...

  • 2007 and newer: correctly for all dates.
  • 2006: incorrectly for dates between the second Sunday in March and first Sunday in April, and between the last Sunday in October and the first Sunday in November.
  • 2005 and older: incorrectly for all dates between the second Sunday in March and first Sunday in November.

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.



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 razorcat