diff --git a/django/utils/datetime_safe.py b/django/utils/datetime_safe.py index a048ecd066..b634888092 100644 --- a/django/utils/datetime_safe.py +++ b/django/utils/datetime_safe.py @@ -4,7 +4,7 @@ # # Based on code submitted to comp.lang.python by Andrew Dalke # -# >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%M/%d was a %A") +# >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%m/%d was a %A") # '1850/08/02 was a Friday' from datetime import date as real_date, datetime as real_datetime @@ -83,7 +83,7 @@ def strftime(dt, fmt): sites.append(site) s = s1 - syear = "%4d" % (dt.year,) + syear = "%04d" % (dt.year,) for site in sites: s = s[:site] + syear + s[site+4:] return s diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py index 45d57e58d4..a3ff87353e 100644 --- a/tests/modeltests/serializers/models.py +++ b/tests/modeltests/serializers/models.py @@ -277,6 +277,21 @@ None >>> print obj +# Regression for #12524 -- dates before 1000AD get prefixed 0's on the year +>>> a = Article.objects.create( +... pk=4, +... author = jane, +... headline = "Nobody remembers the early years", +... pub_date = datetime(1, 2, 3, 4, 5, 6)) + +>>> serialized = serializers.serialize("json", [a]) +>>> print serialized +[{"pk": 4, "model": "serializers.article", "fields": {"headline": "Nobody remembers the early years", "pub_date": "0001-02-03 04:05:06", "categories": [], "author": 2}}] + +>>> obj = list(serializers.deserialize("json", serialized))[0] +>>> print obj.object.pub_date +0001-02-03 04:05:06 + """} try: diff --git a/tests/regressiontests/datetime_safe/__init__.py b/tests/regressiontests/datetime_safe/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/regressiontests/datetime_safe/models.py b/tests/regressiontests/datetime_safe/models.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/regressiontests/datetime_safe/tests.py b/tests/regressiontests/utils/datetime_safe.py similarity index 83% rename from tests/regressiontests/datetime_safe/tests.py rename to tests/regressiontests/utils/datetime_safe.py index e1fe2b0f0e..6c3e7df359 100644 --- a/tests/regressiontests/datetime_safe/tests.py +++ b/tests/regressiontests/utils/datetime_safe.py @@ -1,4 +1,4 @@ -r""" +""" >>> from datetime import date as original_date, datetime as original_datetime >>> from django.utils.datetime_safe import date, datetime >>> just_safe = (1900, 1, 1) @@ -34,4 +34,11 @@ True '00' >>> datetime(*just_safe).strftime('%y') '00' + +>>> date(1850, 8, 2).strftime("%Y/%m/%d was a %A") +'1850/08/02 was a Friday' + +# Regression for #12524 -- Check that pre-1000AD dates are padded with zeros if necessary +>>> date(1, 1, 1).strftime("%Y/%m/%d was a %A") +'0001/01/01 was a Monday' """ diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py index 56d41b9ae6..96b7b4d298 100644 --- a/tests/regressiontests/utils/tests.py +++ b/tests/regressiontests/utils/tests.py @@ -9,6 +9,7 @@ from django.utils.functional import SimpleLazyObject import timesince import datastructures +import datetime_safe import itercompat import tzinfo @@ -26,6 +27,7 @@ except NameError: __test__ = { 'timesince': timesince, 'datastructures': datastructures, + 'datetime_safe': datetime_safe, 'itercompat': itercompat, 'tzinfo': tzinfo, }