top | item 39554853

(no title)

aiiane | 2 years ago

What is your definition of "subtracting a year"? Seems like that's a relatively ambiguous operation without more specification.

discuss

order

Ensorceled|2 years ago

Can you think of any situation where subtracting a year from today's date is ambiguous when today isn't, well, today?

aiiane|2 years ago

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.

OJFord|2 years ago

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.

kccqzy|2 years ago

Since they mentioned a clean up script, I assume they could easily just use 365 days for that use case.

hinkley|2 years ago

But then it'll be off by one day for the rest of this year. And someone will notice that they no longer have March 1 2023-March 1 2024 in their chart, but March 2 2023

ddgflorida|2 years ago

Plenty of thought has gone into this. Look at what database date functions do when you ask it to subtract 1 year. I will agree that there is not one answer.

adrianmonk|2 years ago

It is ambiguous, but one part that's pretty unambiguous is that the result should be a date, not a crash.