The problem with the last fix for the timezone bug was that we constructed a new Date object using
new Date(2010, 0, 1, 0, 0, 0)
which is midnight on the 1st of January 2010 in local time.
Suppose we are trying to construct the date 2019-04-05. If your timezone is UTC+1, it goes something like this:
- Construct a new Date(2010, 0, 1, 0, 0, 0)
00:00 2010-01-01 in your local timezone and 23:00 2009-12-31 in UTC
- Set UTC year to 2019
23:00 2019-12-31 in UTC
(That's 00:00 2020-01-01 in your local timezone)
- Set UTC month to April
23:00 2019-04-31 in UTC
Oh no! April doesn't have 31 days. JavaScript will helpfully convert this to the next day, i.e. 2019-05-01.
- Set UTC day to 5
23:00 2019-05-05 in UTC
Shit, we have the wrong month.
The solution is to do what we thought we were doing before, which is to construct a new Date object using UTC:
new Date(Date.UTC(2010, 0, 1, 0, 0, 0))