Skip to content

Instantly share code, notes, and snippets.

@RHolland13
Last active March 19, 2019 22:20
Show Gist options
  • Save RHolland13/a29679a95edd8e01b6b14ca9b5041ffb to your computer and use it in GitHub Desktop.
Save RHolland13/a29679a95edd8e01b6b14ca9b5041ffb to your computer and use it in GitHub Desktop.

Here’s a simple test for historical DST transition support in IE, which exposes a gap in support for America/Chicago as recently as 1986, which we would need to support in order to allow entering something as commonplace as a birthdate.\

What we’re going to do is create a date object for 1:30 am, on April 27, 1986 (30 minutes before the spring forward transition), and add one hour to it, which should give us 3:30 am (since the 2:00 to 3:00 hour is skipped).

Open https://date-fns.org/docs/Getting-Started in IE, and paste this line into the console:

dateFns.getHours(dateFns.addHours(dateFns.parse('1986-04-27T01:30:00', 'yyyy-MM-ddTH:mm:ss', new Date()),1))

On its own, date-fns uses the built-in date object, which does not correctly support the DST transition time (it assumes the transition already happened earlier in the month, because it is back-filling from a starting point after the DTS transition date was changed, because its internal tz database doesn’t go back that far).

Then go to https://momentjs.com/timezone/ and paste this line:

moment.tz('1986-04-27T01:30:00', 'America/Chicago').add(1, 'h').get('h')

Since moment has a full tz database, it handles this correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment