this post was submitted on 06 Nov 2023
31 points (69.1% liked)

Programmer Humor

32472 readers
467 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 1 year ago (1 children)

Have you never done Datetime math before?

You didn't run new Date(2019, 02, 31), you asked it for one month from January 31st.
One month after any given day of the month is, by most people's intuition, a valid thing to ask for.

Your solution of making the API throw an exception for every 31st of the year is vastly less intuitive to me than "a month is 31 days in January, and 28 or 29 in February, so adding a month does different things in different months", because at least for those is can also query how many days are in the month.

If I say to add four days, will it throw an exception if it's the 31st? No month has 35 days, so I should get an exception, right?
Or is it just this weird caveat around months? Does it apply to time?