2 ms·
Can you think of any situation where subtracting a year from today's date is ambiguous when today isn't, well, today?
by Ensorceled 3y ago
Can you think of any situation where subtracting a year from today's date is ambiguous when today isn't, well, today?
- aiiane 3y agoYes - 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.
- JohnFen 3y agoWorth a mention... Falsehoods Programmers Believe About Time: https://news.ycombinator.com/item?id=4128208 https://news.ycombinator.com/item?id=4128208
- OJFord 3y agoMoving 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.
- chatmasta 3y agoYou 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.
- OJFord 3y agoAnd as I just learnt elsewhere in this thread, it would actually be three four-hundredths less than that anyway, i.e. 365.2425, since only one in four centenaries is a leap year.