Skip to content

Adding and removing one day using addDays doesn't return original date #2742

Answered by fturmel
punksta asked this question in Q&A
Discussion options

You must be logged in to vote

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+0…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by kossnocorp
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2736 on November 02, 2021 09:32.