• rtxn@lemmy.world
      link
      fedilink
      arrow-up
      19
      arrow-down
      1
      ·
      1 day ago

      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.

    • Eager Eagle@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      edit-2
      23 hours 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)?

    • wols@lemmy.zip
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      1 day ago

      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.

      • Eager Eagle@lemmy.world
        link
        fedilink
        English
        arrow-up
        4
        ·
        24 hours 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.