summaryrefslogtreecommitdiff
path: root/tests/regressiontests/utils/dateformat.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-05-08 13:39:37 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-05-08 13:39:37 +0000
commit2af75b485db15a8494b040aa04337c052b896cca (patch)
treefc4f74a3940a645a8915160cf27f384d55b7f29b /tests/regressiontests/utils/dateformat.py
parentf7d01c49e95a9ed25dd75e6b3d4c063dff58e23a (diff)
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
Diffstat (limited to 'tests/regressiontests/utils/dateformat.py')
-rw-r--r--tests/regressiontests/utils/dateformat.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/regressiontests/utils/dateformat.py b/tests/regressiontests/utils/dateformat.py
new file mode 100644
index 0000000000..63b8201752
--- /dev/null
+++ b/tests/regressiontests/utils/dateformat.py
@@ -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()