Opened 8 years ago

Closed 8 years ago

#27662 closed Bug (duplicate)

test suite fails in the last week of a leap year

Reported by: Hartmut Goebel Owned by: nobody
Component: Utilities Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running the test suite in the last week of a leap year, some tests fail. This is due to a subtle bug in timesince().

This bug only occurs if "now" is in a leap year and "d" (the date to be compared with now) is not. The test suite contains tests for comparing "now" with "now+oneweek", which is why this test fails only in the last week of a lead year.

This test-case test for this bug. Just add it to "tests/utils_tests/test_timesince.py":

    def test_year_boundry_current_is_leapyear(self):
        "Current year is a leap year, and next week is in next year"
        today = datetime.date(2016, 12, 28) # within the last week of a leap year
        self.assertEqual(timeuntil(today + self.oneweek, today), '1\xa0week')

"today" (2016) is in a leap year, while "today+oneweek" will be 2017-01-05 which is not in a leap year.

The bug is caused by django/utils/timesince.py, line 46:

   delta -= datetime.timedelta(calendar.leapdays(d.year, now.year))

Change History (1)

comment:1 by Tim Graham, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #27637 (already fixed in master, stable/1.10.x, and stable/1.9.x branches).

Note: See TracTickets for help on using tickets.
Back to Top