-
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
It adds extra hours for some dates. |
Beta Was this translation helpful? Give feedback.
-
@punksta @tan75 Here's a nodejs version that should be reproducible for anyone: import { addDays } from 'date-fns';
process.env.TZ = 'CET';
// bug
const date1 = new Date(2060, 2, 27, 2);
const res1 = addDays(date1, 1);
console.log(date1.toString()); // Sat Mar 27 2060 02:00:00 GMT+0100 (GMT+01:00)
console.log(res1.toString()); // Sun Mar 28 2060 03:00:00 GMT+0200 (GMT+02:00)
// OK
const date2 = new Date(2060, 2, 27, 3);
const res2 = addDays(date2, 1);
console.log(date2.toString()); // Sat Mar 27 2060 03:00:00 GMT+0100 (GMT+01:00)
console.log(res2.toString()); // Sun Mar 28 2060 03:00:00 GMT+0200 (GMT+02:00)
// also OK as expected, we didn't cross over to DST
const date3 = new Date(2060, 2, 27, 1);
const res3 = addDays(date3, 1);
console.log(date3.toString()); // Sat Mar 27 2060 01:00:00 GMT+0100 (GMT+01:00)
console.log(res3.toString()); // Sun Mar 28 2060 01:00:00 GMT+0100 (GMT+01:00)
|
Beta Was this translation helpful? Give feedback.
-
Sorry everyone, I realized something interesting just now and it's not a bug after all. The datetime you were landing on actually doesn't even technically exist because of the DST shift. The JS Date object resolves it to the next hour automatically. process.env.TZ = 'CET';
console.log(new Date(2060, 2, 28, 1, 59, 59, 999).toString());
console.log(new Date(2060, 2, 28, 2).toString());
console.log(new Date(2060, 2, 28, 2, 30).toString()); // resolves to 3:30 am!
console.log(new Date(2060, 2, 28, 3).toString());
// Sun Mar 28 2060 01:59:59 GMT+0100 (GMT+01:00)
// Sun Mar 28 2060 03:00:00 GMT+0200 (GMT+02:00)
// Sun Mar 28 2060 03:30:00 GMT+0200 (GMT+02:00)
// Sun Mar 28 2060 03:00:00 GMT+0200 (GMT+02:00) |
Beta Was this translation helpful? Give feedback.
-
Thank you @fturmel |
Beta Was this translation helpful? Give feedback.
-
In case you are curious how I ended up with these dates. I was writing tests with https://github.com/dubzzz/fast-check for operations with Date objects and it generated these dates. |
Beta Was this translation helpful? Give feedback.
Sorry everyone, I realized something interesting just now and it's not a bug after all.
The datetime you were landing on actually doesn't even technically exist because of the DST shift. The JS Date object resolves it to the next hour automatically.