date-fns / utc

date-fns UTC utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any date-fns function that runs toDate returns wrong outputs

erandagan opened this issue · comments

Description
The toDate function, which many date-fns functions call internally, loses the custom UTC proxy methods.

const x = new UTCDate("2023-07-08T21:00:00.000Z")
x.getDay() // prints 6 
toDate(x).getDay() // prints 0 on machines UTC > +3

Impact
Consider running the following anywhere that is UTC > 3:

const x = new UTCDate("2023-07-08T21:00:00.000Z")
const y = new UTCDate("2023-07-08T00:00:00.000Z")

isSameDay(x,y) // prints false, should be true
startOfDay(x) // prints 2023-07-08
startOfDay(y) // prints 2023-07-07, should be 2023-07-08

This was fixed in date-fns v3 over a year ago, but never pulled back to v2 (which is still the main version)

Closing the issue as there's nothing actionable. date-fns@3.0.0-alpha.1 is out now, stable release's coming. Follow official Twitter for updates: https://twitter.com/date_fns