Every dev team on the planet has at one point run into issues with their test suite or applications from improperly handled dates. Dates that original

It's Time We Kill JS Dates - by Sebastian Kade

submited by
Style Pass
2024-10-17 10:00:07

Every dev team on the planet has at one point run into issues with their test suite or applications from improperly handled dates.

Dates that originally apply to everyone (e.g. this template repeats every Tuesday), but then once created, are in a specific timezone.

Trying to debug with JS Dates is a nightmare because it’s easy to lose track of which timezone your client, server, and database are showing you the date in. (Yes even when force everything in UTC).

non-obvious behaviours – some functions return local time, some UTC (docs constantly have to specify which function uses which).

Depending on where you run this code you will get a different result, because constructing a date without the Z forces the date to be in the local timezone (not obvious).

If you wanted to represent the data 2021-06-02 with a Date, it will always be interpreted as 2021-06-02T00:00:00Z which is not the same thing. undefined !== 0.

Leave a Comment