zonedTimeToUtc() change to summer time at the wrong hour
See original GitHub issueThe change from standard PST (-08:00) to summer time PDT (-07:00) in America/Los_Angeles occurred at 2am on March 8, 2020 local time. As you can see in the test below, moment
handles this correctly by converting 2020-03-08 02:00
local time as well as 2020-03-08 03:00
local time to the same ISO date (2020-03-08T10:00:00.000Z
).
zonedTimeToUtc
however does not change to summer time until 2020-03-08 10:00
local time, which is 8 hours too late. Interestingly 8 hours is the same as the regular PST offeset, so perhaps zonedTimeToUtc
switches over to summertime based on UTC instead of local time, just an idea.
import { zonedTimeToUtc } from 'date-fns-tz';
import moment from 'moment';
import 'moment-timezone';
const times = [
'2020-03-08 02:00', // true 2020-03-08 02:00 d 2020-03-08T10:00:00.000Z m 2020-03-08T10:00:00.000Z
'2020-03-08 03:00', // false 2020-03-08 03:00 d 2020-03-08T11:00:00.000Z m 2020-03-08T10:00:00.000Z
'2020-03-08 04:00', // false 2020-03-08 04:00 d 2020-03-08T12:00:00.000Z m 2020-03-08T11:00:00.000Z
'2020-03-08 05:00', // false 2020-03-08 05:00 d 2020-03-08T13:00:00.000Z m 2020-03-08T12:00:00.000Z
'2020-03-08 06:00', // false 2020-03-08 06:00 d 2020-03-08T14:00:00.000Z m 2020-03-08T13:00:00.000Z
'2020-03-08 07:00', // false 2020-03-08 07:00 d 2020-03-08T15:00:00.000Z m 2020-03-08T14:00:00.000Z
'2020-03-08 08:00', // false 2020-03-08 08:00 d 2020-03-08T16:00:00.000Z m 2020-03-08T15:00:00.000Z
'2020-03-08 09:00', // false 2020-03-08 09:00 d 2020-03-08T17:00:00.000Z m 2020-03-08T16:00:00.000Z
'2020-03-08 10:00', // true 2020-03-08 10:00 d 2020-03-08T17:00:00.000Z m 2020-03-08T17:00:00.000Z
];
times.forEach((t) => {
const d = zonedTimeToUtc(t, 'America/Los_Angeles').toISOString();
const m = moment.tz(t, 'America/Los_Angeles').toDate().toISOString();
console.log(d === m, t, 'd', d, 'm', m);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Wrong time in Windows 10 after daylights saving time.
Click on the "Internet Time" tab. Click on "Change settings…”. 2. Turn on all options, being sure to turn on "Adjust for daylight...
Read more >date-fns-tz - npm
zonedTimeToUtc - Given a date and any time zone, returns a Date with the equivalent UTC time · utcToZonedTime - Get a date/time...
Read more >Daylight Saving Time - When do we change our clocks?
When we change our clocks. Most of the United States begins Daylight Saving Time at 2:00 a.m. on the second Sunday in March...
Read more >Saving time in UTC doesn't work and offsets aren't enough
The problem with scheduled events is that timezones change. "US West Coast Time" shifts by 1 hour twice a year. Egypt canceled DST...
Read more >Daylight saving time and time zone best practices [closed]
@abatishchev - This way GETDATE() on SQL will be UTC (as will DateTime.Now ). And the server will not be effected by any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Huh, you’re correct @lirbank … Either something wrong with my environment or with my perception of time 😄
Some day date-fns will have TZ functionality built-in, some day …
For reference, these all pass, regardless if 2.11.0 or 2.11.1 is used: