date-fns / utc

date-fns UTC utils
70 stars 5 forks source link

Any date-fns function that runs toDate returns wrong outputs #2

Closed erandagan closed 7 months ago

erandagan commented 8 months ago

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)

kossnocorp commented 8 months ago

Yes, I’m aware and I did change it in date-fns v3 which is coming soon. Sorry that it wasn't clear from the docs.

On Mon, Oct 9, 2023, at 20:18, Eran Dagan wrote:

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 startOfDay(x) // prints 2023-07-08 startOfDay(y) // prints 2023-07-07

— Reply to this email directly, view it on GitHub https://github.com/date-fns/utc/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMX2JA7RK7JZ3MZECJIDDX6PTTFAVCNFSM6AAAAAA5YWV5Z6VHI2DSMVQWIX3LMV43ASLTON2WKOZRHEZTEOJUGIYTEMI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

kossnocorp commented 7 months ago

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