you are viewing a single comment's thread
view the rest of the comments
[–] 26 points 1 year ago (14 children)

The python version seems buggy as fuck. Depending on which year you run it it's off by 1-3 days

  • source
  • hideshow 14 child comments
  • [–] 8 points 1 year ago (3 children)

    Python does have a year option that they are not using. Depending on the application I would use 365 for a year to get a consistent number of days.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 1 point 1 year ago* (1 child)

    Python does have a year option that they are not using.

    No, it doesn't:

    help(datetime.timedelta)

    Help on class timedelta in module datetime:
    
    class timedelta(builtins.object)
     |  Difference between two datetime values.
     |
     |  timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
     |
     |  All arguments are optional and default to 0.
     |  Arguments may be integers or floats, and may be positive or negative.
    

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year ago (9 children)

    That sounds serious, can you give some example values we can test?

  • source
  • parent
  • hideshow 9 child comments
  • [–] 13 points 1 year ago (6 children)

    look I'm not trying to be a dick or anything, but do you not know about leap years and which years they are?

  • source
  • parent
  • hideshow 6 child comments
  • [–] 2 points 1 year ago (4 children)
  • [–] 5 points 1 year ago* (last edited 1 year ago) (2 children)

    Leap years are each fourth year, except each hundredth year, except each thousandth fourhundredth year.

    1896 leap year
    1900 not leap year
    1904 leap year
    ...
    1996 leap year
    2000 leap year
    2004 leap year
    ...
    2096 leap year
    2100 not leap year
    2104 leap year

    Then you just arrange the 10 year window in different positions to overlap 1 to 3 leap years to reveal the three outcomes of the bug.

    - / - - - / - - - /
    - - / - - - / - - -
    - - 0 - - - / - - -

    - is a normal year, / is a leap year, 0 is an exceptional non-leap year.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 1 year ago (1 child)

    Small correction, it's every fourth year except every hundreth year except every 400th year. I'm assuming the misconception comes from the last time it was a 100th also being a 1000th (2000) but the next time a leap year will end in 00 is 2400

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 1 year ago

    Ahh right! Thanks for correcting me. Now that you mention it I remember too. It also makes sense, a year is roughly 365.2425 days long. Add 0.25 (one out of four), subtract 0.01 (one out of hundred), add another 0.0025 (2.5 out of thousand which is 1 out of 400)

  • source
  • parent