Daylight saving is not being considered while using date-fns
See original GitHub issueThe offset is not considering for pacific timezone. Right now we are in PDT but the timezone always formats the time according to PST. Rather than using GMT-07:00 rather I always end up getting GMT-08:00. The example is mentioned below
require("date-fns/package.json"); // date-fns is a peer dependency.
var dateFnsTz = require("date-fns-tz")
const laTimeZone = 'America/Los_Angeles'
const laDate = dateFnsTz.utcToZonedTime(new Date('2020-02-02T06:59:00z'), laTimeZone);
console.log(laDate)
// WRONG RESULT - Sat Feb 01 2020 22:59:00 GMT-0800 (Pacific Standard Time)
// CORRECT RESULT - Sat Feb 01 2020 23:59:00 GMT-0700 (Pacific Standard Time)
Is there any way to accommodate the DST along with the timezone
Issue Analytics
- State:
- Created 3 years ago
- Reactions:17
- Comments:11
Top Results From Across the Web
Add a day via date-fns considering time zone change
UTC doesn't have daylight saving, nor is it a timezone. When you add a day using local methods and cross a daylight saving...
Read more >Date-fns is returning incorrect dates - The freeCodeCamp Forum
Daylight saving is not being considered while using date -fns The offset is not considering for pacific timezone. Right now we are in...
Read more >How to handle Time Zones in JavaScript - Bits and Pieces
With almost 140 functions, Date-fn is referred to be Lodash for dates. Date-fns can have the following advantages : Immutable and pure; Native ......
Read more >date-fns - modern JavaScript date utility library
date -fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >Date.prototype.getTimezoneOffset() - JavaScript | MDN
In a region that annually shifts in and out of Daylight Saving Time (DST), as date varies, the number of minutes returned by...
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
Use parse in order to parse a date do not use new Date. new Date actually attaches the timezone information alongside and that kinda messes things up. Use ‘yyyy-MM-dd'T'HH:mm:ss.SSSz’ to parse your date and then do the required. Let me know if you find proper results.
You can refer https://runkit.com/shivkumarganesh/daylightsavingissue
var df = require("date-fns") var dateFnsTz = require("date-fns-tz") const parsedDate = df.parse("2020-10-19T00:00:00.000Z","yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'",new Date()); const utcDate = dateFnsTz.zonedTimeToUtc(parsedDate, 'Europe/Madrid'); console.log(utcDate.toISOString()) // 2020-10-18T22:00:00.000Z
We are having almost the same problem, but when converting
zonedTimeToUtc
:This is wrong as it should be
2020-10-18T22:00:00.000Z
, -1 for being in Madrid and -1 for being in DST.