Commit d751f2ca authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

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

[1.1.X] Fixed #12524 -- Clarified handling of pre-1000AD dates in datetime_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
parent 1d9bc595
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
+15 −0
Original line number Diff line number Diff line
@@ -277,6 +277,21 @@ None
>>> 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:
+0 −0

Empty file deleted.

+0 −0

Empty file deleted.

+8 −1
Original line number Diff line number Diff line
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'
"""
Loading