this post was submitted on 06 Nov 2023
30 points (68.3% liked)

Programmer Humor

32464 readers
687 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
[–] ricecake@sh.itjust.works 3 points 1 year ago (1 children)

In this case though, it's consistent, and is just one of the annoying ways the problem could be solved. Datetime math is just fucked up.

You can just not support that functionality, which gives you people making their own mistakes and forgetting leap years or hard coding all sorts of insanity.

You can clamp the value to the end of the month, but that gives you the odd case where date + month - month != date in some days, which is also a weird pitfall.

If I see any code dealing with adding and subtracting months, I'm either checking the manual or I already know it's behavior from doing so before.
I'm all about not liking how JS does stuff, but Datetime math is the one area where in willing to forgive most insanity of outcomes.