#19210: django.utils.timesince() does not account for leap years
---------------------------+------------------------------------
     Reporter:  jnns       |                    Owner:  raphaelm
         Type:  Bug        |                   Status:  assigned
    Component:  Utilities  |                  Version:  master
     Severity:  Normal     |               Resolution:
     Keywords:  date time  |             Triage Stage:  Accepted
    Has patch:  1          |      Needs documentation:  0
  Needs tests:  0          |  Patch needs improvement:  0
Easy pickings:  0          |                    UI/UX:  0
---------------------------+------------------------------------
Changes (by raphaelm):

 * needs_better_patch:  1 => 0


Comment:

 After looking into a lot of algorithms for date diffing, including the
 ones suggested above and the ones from `python-dateutil` (which get pretty
 complex) I decided to go for the most simple solution I could find. I
 assume `timesince` wasn't ever meant to be an calculation. If we would
 want an exact calculation, we should completely re-implement it to
 correctly work with the different number of days in the months and so on.

 However, there is a very simple fix to the accumulated error that grows
 with the given time period: just use `calendar.leapdays` from the standard
 library and substract it from the number of days.

 I created a pull request including a regression test:
 https://github.com/django/django/pull/4785

--
Ticket URL: <https://code.djangoproject.com/ticket/19210#comment:18>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/062.cf459dd8fd6cb1952c1743b15ab3758d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to