this post was submitted on 24 Aug 2025
456 points (98.9% liked)

Programmer Humor

25958 readers
903 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Diplomjodler3@lemmy.world 46 points 1 day ago (4 children)

The Python won't give an accurate date here because it doesn't take into account leap years.

[–] rtxn@lemmy.world 24 points 1 day ago (2 children)

timedelta marks time in days, seconds, and microseconds. It doesn't take leap years into account because the concept of years is irrelevant to timedelta. If you need to account for leap years, you need a different API.

[–] nilloc@discuss.tchncs.de 1 points 5 hours ago

365.25*10 would at least get you closer.

[–] Randelung@lemmy.world 1 points 15 hours ago

You can subtract two dates and get the exact time difference.

[–] wols@lemmy.zip 11 points 1 day ago (2 children)

The comparison is somewhat awkward, because the rails example presumably produces a date, while the python one is referring to an interval of time.
Just from the meme it's not obvious which was the actual intended use, so labeling either as inaccurate requires us to make assumptions.

Personally, the concept of "10 years ago" is a bit nebulous to me. If today is February 29th, is ten years ago March 1st? Doesn't seem right. Or particularly useful.

[–] nilloc@discuss.tchncs.de 1 points 5 hours ago

Ruby should add 10.years.ago.today

[–] eager_eagle@lemmy.world 4 points 1 day ago

yeah, that's pretty much why timedelta doesn't have the concept of months or years, just days and smaller units. I like it better this way.

[–] eager_eagle@lemmy.world 8 points 1 day ago* (last edited 1 day ago)

Because what's accurate here depends on the context, and the Python example doesn't hide that from the programmer.

The same dilemma goes for month calculations: does "3 months ago" mean 90 days ago, 91.3 days ago, this many days into the target month, or this many days from the target month's end (e.g. to account for 28, 29, 30, and 31-day months)?

[–] Blackmist@feddit.uk 3 points 1 day ago

Does the Ruby version do that though?

I haven't got it installed to check, but seeing constants like SECONDS_PER_YEAR in the documentation makes me think it's just as bad if not worse.

https://api.rubyonrails.org/classes/ActiveSupport/Duration.html