Ticket #10825: utils_dateformat-r10651.patch
File utils_dateformat-r10651.patch, 4.2 KB (added by , 16 years ago) |
---|
-
django/utils/dateformat.py
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'\\(.)') … … 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 self.timezone and 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
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/utils/dateformat.py
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
Property changes on: tests\regressiontests\utils\dateformat.py ___________________________________________________________________ Added: svn:eol-style + native
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 … … 22 23 __test__ = { 23 24 'timesince': timesince, 24 25 'datastructures': datastructures, 26 'dateformat': dateformat, 25 27 'itercompat': itercompat, 26 28 } 27 29