288
you are viewing a single comment's thread
view the rest of the comments
[-] waldfee@feddit.org 13 points 1 month ago

crystal is another language that's apparently quite similar to ruby, with the difference of being compiled and staticly type-checked, and I just love it's ruby like syntax. I believe the equivalent code for this in crystal would be Time.local - 10.years

[-] hinterlufer@lemmy.world 2 points 1 month ago

one could certainly implement something like that in python, something like time.now - 10 * time.unit.year

[-] Feathercrown@lemmy.world 1 points 1 month ago

Does this account for leap years?

[-] hinterlufer@lemmy.world 3 points 1 month ago

I don't think this is implemented in the standard datetime library, but in principle overriding sub is easily possible and you can define it as you'd wish.

However, I think subtracting a year is a bit ill defined, because it isn't clear which year you're subtracting given the leap year issue.

[-] Feathercrown@lemmy.world 3 points 1 month ago

If you're subtracting a year from a date, you could just keep the date constant while changing the year, and adjust Feb 29 as needed.

this post was submitted on 24 Aug 2025
288 points (97.7% liked)

Programmer Humor

38555 readers
186 users here now

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

Rules:

founded 6 years ago
MODERATORS