Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #12524 -- Clarified handling of pre-1000AD dates in dat…

…etime_safe (and thus, the serializers). Patch includes moving the datetime_safe tests into the utils regressiontests module. Thanks to gsf for the report and initial patch.

Backport of r12423 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12424 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d751f2cade81b6a8cf325ab5dd081c015f727ef3 1 parent 1d9bc59
@freakboy3742 freakboy3742 authored
View
4 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
View
15 tests/modeltests/serializers/models.py
@@ -277,6 +277,21 @@ def __unicode__(self):
>>> print obj
<DeserializedObject: Soslan Djanaev (1) playing for Spartak Moskva>
+# 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:
View
0  tests/regressiontests/datetime_safe/__init__.py
No changes.
View
0  tests/regressiontests/datetime_safe/models.py
No changes.
View
9 tests/regressiontests/datetime_safe/tests.py → 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 @@
'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'
"""
View
2  tests/regressiontests/utils/tests.py
@@ -10,6 +10,7 @@
import timesince
import datastructures
import dateformat
+import datetime_safe
import itercompat
from decorators import DecoratorFromMiddlewareTests
from functional import FunctionalTestCase
@@ -25,6 +26,7 @@
__test__ = {
'timesince': timesince,
'datastructures': datastructures,
+ 'datetime_safe': datetime_safe,
'itercompat': itercompat,
}
Please sign in to comment.
Something went wrong with that request. Please try again.