Re:Ask HN: Did you encounter any leap year bugs today?
by Ensorceled on Thursday February 29, 2024 @03:57PM
(#39554964)
Can you think of any situation where subtracting a year from today's date is ambiguous when today isn't, well, today?
[ Parent
| on HN ]
Re:Ask HN: Did you encounter any leap year bugs today?
by aiiane on Thursday February 29, 2024 @04:27PM
(#39555345)
Yes - on any day, subtracting a year might mean subtracting the average length of a year (which is a bit more than 365 days), or wanting the same day and month number in the previous calendar year, or wanting the same semantic difference ("last Monday of the month in January"), to name a few possible meanings.
Re:Ask HN: Did you encounter any leap year bugs today?
by JohnFen on Thursday February 29, 2024 @04:50PM
(#39555652)
Worth a mention... Falsehoods Programmers Believe About Time: https://news.ycombinator.com/item?id=4128208
Re:Ask HN: Did you encounter any leap year bugs today?
by OJFord on Thursday February 29, 2024 @05:38PM
(#39556179)
Moving bank/festive holidays, first Monday of the year(, first work day of the year not Monday if that's NYD and bank holiday), lunar occasions.
'subtract a year' is imprecise and has many meanings, if what you want is 'same day, same month, previous year' then say that and do that, that's conceptually `date.year -= 1` not `date -= 1 year`, and will have this bug.
Re:Ask HN: Did you encounter any leap year bugs today?
by chatmasta on Thursday February 29, 2024 @06:15PM
(#39556470)
You could subtract 365.25 days, but then you're left with a new problem: just because you can amortize a leap day over four years doesn't mean that you get an extra 6 hours each year.