You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe it's working as intended. Your initial datetime is 3AM the 29th in IDT (midnight UTC), and when doing the minus one day operation we land on the 28th at 3AM IST.
Regarding your linked issue, 24 hours !== 1 day during a daylight saving transition. If you substract 24 hours from your date, you will land on the 28th at 2AM IST.
// process.env.TZ = 'Asia/Jerusalem';import{subDays,subHours}from'date-fns';constdate=newDate('2024-03-29T00:00:00.000Z');constdateMinusOneDay=subDays(date,1);constdateMinus24Hours=subHours(date,24);console.log(date.toISOString(),date.getTimezoneOffset());// 2024-03-29T00:00:00.000Z -180console.log(date.toString());// Fri Mar 29 2024 03:00:00 GMT+0300 (Israel Daylight Time)console.log(dateMinusOneDay.toISOString(),dateMinusOneDay.getTimezoneOffset());// 2024-03-28T01:00:00.000Z -120console.log(dateMinusOneDay.toString());// Thu Mar 28 2024 03:00:00 GMT+0200 (Israel Standard Time)console.log(dateMinus24Hours.toISOString(),dateMinus24Hours.getTimezoneOffset());// 2024-03-28T00:00:00.000Z -120console.log(dateMinus24Hours.toString());// Thu Mar 28 2024 02:00:00 GMT+0200 (Israel Standard Time)
Bonus: if you wanted the operation to happen in UTC instead, have a look at the UTCDate companion library.
Using latest version (3.6.0) for removing days
Which is Israel Daylight Time
Which is Israel Standard Time
According to #1302 (comment) adding/removing days are supposed to respect timezone changes
Am I missing something?
The text was updated successfully, but these errors were encountered: