Ticket #10825: 10825.diff
File 10825.diff, 4.5 KB (added by , 16 years ago) |
---|
-
django/utils/dateformat.py
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index 2751d82..f5edf42 100644
a b from django.utils.tzinfo import LocalTimezone 16 16 from django.utils.translation import ugettext as _ 17 17 from django.utils.encoding import force_unicode 18 18 from calendar import isleap, monthrange 19 import re, time 19 import re 20 from calendar import timegm 21 from time import mktime 20 22 21 23 re_formatchars = re.compile(r'(?<!\\)([aAbBdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])') 22 24 re_escaped = re.compile(r'\\(.)') … … class DateFormat(TimeFormat): 199 201 200 202 def U(self): 201 203 "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)" 202 off = self.timezone and self.timezone.utcoffset(self.data) or 0 203 return int(time.mktime(self.data.timetuple())) + off.seconds * 60 204 if getattr(self.data, 'tzinfo', None): 205 return int(timegm(self.data.utctimetuple())) 206 else: 207 return int(mktime(self.data.timetuple())) 204 208 205 209 def w(self): 206 210 "Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)" -
docs/ref/templates/builtins.txt
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index f4e49a9..e06d28d 100644
a b Available format strings: 506 506 month, 2 characters. 507 507 t Number of days in the given month. ``28`` to ``31`` 508 508 T Time zone of this machine. ``'EST'``, ``'MDT'`` 509 U Not implemented. 509 U Seconds since the Unix Epoch 510 (January 1 1970 00:00:00 UTC). 510 511 w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday) 511 512 leading zeros. 512 513 W ISO-8601 week number of year, with ``1``, ``53`` -
tests/regressiontests/dateformat/tests.py
diff --git a/tests/regressiontests/dateformat/tests.py b/tests/regressiontests/dateformat/tests.py index 481e36a..d649d47 100644
a b u'th' 37 37 u'31' 38 38 >>> no_tz or format(my_birthday, 'T') == 'CET' 39 39 True 40 >>> no_tz or format(my_birthday, 'U') == '300 531600'40 >>> no_tz or format(my_birthday, 'U') == '300315600' 41 41 True 42 42 >>> format(my_birthday, 'w') 43 43 u'0' -
new file tests/regressiontests/utils/dateformat.py
diff --git a/tests/regressiontests/utils/dateformat.py b/tests/regressiontests/utils/dateformat.py new file mode 100644 index 0000000..63b8201
- + 1 """ 2 >>> from datetime import datetime, date 3 >>> from django.utils.dateformat import format 4 >>> from django.utils.tzinfo import FixedOffset, LocalTimezone 5 6 # date 7 >>> d = date(2009, 5, 16) 8 >>> date.fromtimestamp(int(format(d, 'U'))) == d 9 True 10 11 # Naive datetime 12 >>> dt = datetime(2009, 5, 16, 5, 30, 30) 13 >>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt 14 True 15 16 # datetime with local tzinfo 17 >>> ltz = LocalTimezone(datetime.now()) 18 >>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz) 19 >>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt 20 True 21 >>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.replace(tzinfo=None) 22 True 23 24 # datetime with arbitrary tzinfo 25 >>> tz = FixedOffset(-510) 26 >>> ltz = LocalTimezone(datetime.now()) 27 >>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz) 28 >>> datetime.fromtimestamp(int(format(dt, 'U')), tz) == dt 29 True 30 >>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt 31 True 32 >>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.astimezone(ltz).replace(tzinfo=None) 33 True 34 >>> datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple() == dt.utctimetuple() 35 True 36 >>> datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple() == dt.utctimetuple() 37 True 38 39 # Epoch 40 >>> utc = FixedOffset(0) 41 >>> udt = datetime(1970, 1, 1, tzinfo=utc) 42 >>> format(udt, 'U') 43 u'0' 44 """ 45 46 if __name__ == "__main__": 47 import doctest 48 doctest.testmod() -
tests/regressiontests/utils/tests.py
diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py index 485c5fa..6d345d9 100644
a b from django.utils import html, checksums 8 8 9 9 import timesince 10 10 import datastructures 11 import dateformat 11 12 import itercompat 12 13 from decorators import DecoratorFromMiddlewareTests 13 14 … … except NameError: 22 23 __test__ = { 23 24 'timesince': timesince, 24 25 'datastructures': datastructures, 26 'dateformat': dateformat, 25 27 'itercompat': itercompat, 26 28 } 27 29