test_distance_of_time_in_words fails before a leap year

Issue #61 new
Andrey Rakhmatullin
created an issue

self.assertEqual("1 year", distance_of_time_in_words(0, 31536000)) fails now with "AssertionError: '1 year' != '11 months and 30 days'" because 31536000 is 365 days, and one full year from now is 366 days.

Comments (6)

  1. Mike Orr

    Fixed in 68639fc711eb. The test tests the interval between "now" and "a year from now". This fails if this year or next year is a leap year. Adjusted the test to first try it as a non-leap year, then if that fails to try it again as a leap year.

  2. David Malcolm

    Debian's bug tracker entry for this http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=629699 notes that distance_of_time_in_words returns different values depending on the current time (and timezone):

    $ export TZ=Europe/Warsaw
    $ for d in 01-01 03-01 03-02 03-27 04-02 10-30; do faketime "2011-$d UTC" python -c 'import webhelpers.date as d; print d.distance_of_time_in_words(0, 31536000)'; done
    1 year
    11 months and 28 days
    11 months and 30 days
    11 months, 30 days and 1 hour
    11 months and 29 days
    11 months, 29 days and 23 hours

    FWIW, I'm also tracking this downstream for Fedora, as https://bugzilla.redhat.com/show_bug.cgi?id=715831

  3. Log in to comment