
-
You should never, ever do date math naively like this. There are too many unexpected edge case, especially between time zones or daylight savings time or leap years, but even without them: https://moment.github.io/luxon/#/math
In fact I would strongly argue you should never use the JS Date built-in at all because they are terrible. Use a library like Luxon or date-fns. As a frontend dev, this is the most common category of bugs I've dealt with in my career, and I've spent dozens of hours fixing other people's datetime handling because of how poorly implemented the JS Date API is. It's full of minefields and gotchas.
The Temporal API is supposed to fix some issues, but that's been in development for like a decade now.
-
Nutrient
Nutrient - The #1 PDF SDK Library. Bad PDFs = bad UX. Slow load times, broken annotations, clunky UX frustrates users. Nutrient’s PDF SDKs gives seamless document experiences, fast rendering, annotations, real-time collaboration, 100+ features. Used by 10K+ devs, serving ~half a billion users worldwide. Explore the SDK for free.
-
-
Very relatedly, there's a potential similar footgun related to hours, due to the fact that dates initialized without hour default to 00:00 in your local timezone.
It's possible then to change the date, and the time will jump to 23:00 due to timezone DST changes.
Example bug I had in 2014 when Russian timezone definitions have changed:
https://github.com/yui/yui2/pull/15