Ticket #17937: timeuntil2.diff

File timeuntil2.diff, 1.4 KB (added by dreamiurg, 13 years ago)
  • django/utils/timesince.py

    diff --git a/django/utils/timesince.py b/django/utils/timesince.py
    index 511acb5..3eb3405 100644
    a b def timeuntil(d, now=None):  
    5757    Like timesince, but returns a string measuring the time until
    5858    the given time.
    5959    """
     60    # Convert datetime.date to datetime.datetime for comparison.
     61    if not isinstance(d, datetime.datetime):
     62        d = datetime.datetime(d.year, d.month, d.day)
     63
    6064    if not now:
    6165        now = datetime.datetime.now(utc if is_aware(d) else None)
    6266    return timesince(now, d)
  • tests/regressiontests/utils/timesince.py

    diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py
    index b0f94d1..eb44d8b 100644
    a b class TimesinceTests(unittest.TestCase):  
    9999        self.assertEqual(timesince(now_tz), u'0 minutes')
    100100        self.assertEqual(timeuntil(now_tz, now_tz_i), u'0 minutes')
    101101
     102    def test_date_object(self):
     103        """ Timesince and timeuntil should work with date objects (#17937 ) """
     104        today = datetime.date.today()
     105        self.assertEqual(timeuntil(today-self.oneday), u'0 minutes')
     106        self.assertEqual(timesince(today+self.oneday), u'0 minutes')
     107
    102108    def test_both_date_objects(self):
    103109        """ Timesince should work with both date objects (#9672) """
    104110        today = datetime.date.today()
Back to Top