1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #10825: fixed the 'U' format code to dateformat (and the date/now filter/tag). Thanks to gsong and mir.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10716 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss
2009-05-08 13:39:37 +00:00
parent f7d01c49e9
commit 2af75b485d
5 changed files with 64 additions and 10 deletions

View File

@@ -0,0 +1,48 @@
"""
>>> from datetime import datetime, date
>>> from django.utils.dateformat import format
>>> from django.utils.tzinfo import FixedOffset, LocalTimezone
# date
>>> d = date(2009, 5, 16)
>>> date.fromtimestamp(int(format(d, 'U'))) == d
True
# Naive datetime
>>> dt = datetime(2009, 5, 16, 5, 30, 30)
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt
True
# datetime with local tzinfo
>>> ltz = LocalTimezone(datetime.now())
>>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=ltz)
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.replace(tzinfo=None)
True
# datetime with arbitrary tzinfo
>>> tz = FixedOffset(-510)
>>> ltz = LocalTimezone(datetime.now())
>>> dt = datetime(2009, 5, 16, 5, 30, 30, tzinfo=tz)
>>> datetime.fromtimestamp(int(format(dt, 'U')), tz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz) == dt
True
>>> datetime.fromtimestamp(int(format(dt, 'U'))) == dt.astimezone(ltz).replace(tzinfo=None)
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), tz).utctimetuple() == dt.utctimetuple()
True
>>> datetime.fromtimestamp(int(format(dt, 'U')), ltz).utctimetuple() == dt.utctimetuple()
True
# Epoch
>>> utc = FixedOffset(0)
>>> udt = datetime(1970, 1, 1, tzinfo=utc)
>>> format(udt, 'U')
u'0'
"""
if __name__ == "__main__":
import doctest
doctest.testmod()