Ticket #11321: 11321-r11173.3.diff
File 11321-r11173.3.diff, 3.4 KB (added by , 15 years ago) |
---|
-
django/contrib/humanize/templatetags/humanize.py
2 2 from django.utils.encoding import force_unicode 3 3 from django import template 4 4 from django.template import defaultfilters 5 from datetime import date 5 from datetime import date, datetime 6 6 import re 7 7 8 8 register = template.Library() … … 80 80 present day returns representing string. Otherwise, returns a string 81 81 formatted according to settings.DATE_FORMAT. 82 82 """ 83 try: 83 try: 84 tzinfo = getattr(value, 'tzinfo', None) 84 85 value = date(value.year, value.month, value.day) 85 86 except AttributeError: 86 87 # Passed value wasn't a date object … … 88 89 except ValueError: 89 90 # Date arguments out of range 90 91 return value 91 delta = value - date.today() 92 delta = value - datetime.now(tzinfo).\ 93 replace(microsecond=0, second=0, minute=0, hour=0).date() 92 94 if delta.days == 0: 93 95 return _(u'today') 94 96 elif delta.days == 1: -
tests/regressiontests/humanize/timezone.py
1 from datetime import tzinfo, timedelta 2 3 class FixedOffset(tzinfo): 4 """Fixed offset in hours east from UTC.""" 5 6 def __init__(self, offset, name): 7 self.__offset = timedelta(hours=offset) 8 self.__name = name 9 10 def utcoffset(self, dt): 11 return self.__offset 12 13 def tzname(self, dt): 14 return self.__name 15 16 def dst(self, dt): 17 return timedelta(0) -
tests/regressiontests/humanize/tests.py
59 59 tomorrow = today + timedelta(days=1) 60 60 someday = today - timedelta(days=10) 61 61 notdate = u"I'm not a date value" 62 62 63 63 test_list = (today, yesterday, tomorrow, someday, notdate) 64 64 someday_result = defaultfilters.date(someday) 65 65 result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'), 66 66 someday_result, u"I'm not a date value") 67 67 self.humanize_tester(test_list, result_list, 'naturalday') 68 69 def test_naturalday_tz(self): 70 from datetime import datetime 71 from django.contrib.humanize.templatetags.humanize import naturalday 72 from timezone import FixedOffset 73 74 today = date.today() 75 76 tz_one = FixedOffset(-12, 'TzOne') 77 tz_two = FixedOffset(12, 'TzTwo') 68 78 79 # Can be today or yesterday 80 date_one = datetime(today.year, today.month, today.day, tzinfo=tz_one) 81 naturalday_one = naturalday(date_one) 82 # Can be today or tomorrow 83 date_two = datetime(today.year, today.month, today.day, tzinfo=tz_two) 84 naturalday_two = naturalday(date_two) 85 86 # As 24h of difference they will never be the same 87 self.assertNotEqual(naturalday_one, naturalday_two) 88 69 89 if __name__ == '__main__': 70 90 unittest.main() 71 91