Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[1.2.X] Fixed #14132 -- Fixed feedgenerator to support years < 1900. …
…Thanks, mk.

Backport from trunk (r15503).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15510 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jezdez committed Feb 12, 2011
1 parent 90ee3af commit 89c03dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion django/utils/feedgenerator.py
Expand Up @@ -27,8 +27,11 @@
import urlparse import urlparse
from django.utils.xmlutils import SimplerXMLGenerator from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_unicode, iri_to_uri from django.utils.encoding import force_unicode, iri_to_uri
from django.utils import datetime_safe


def rfc2822_date(date): def rfc2822_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
# We do this ourselves to be timezone aware, email.Utils is not tz aware. # We do this ourselves to be timezone aware, email.Utils is not tz aware.
if date.tzinfo: if date.tzinfo:
time_str = date.strftime('%a, %d %b %Y %H:%M:%S ') time_str = date.strftime('%a, %d %b %Y %H:%M:%S ')
Expand All @@ -40,6 +43,8 @@ def rfc2822_date(date):
return date.strftime('%a, %d %b %Y %H:%M:%S -0000') return date.strftime('%a, %d %b %Y %H:%M:%S -0000')


def rfc3339_date(date): def rfc3339_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
if date.tzinfo: if date.tzinfo:
time_str = date.strftime('%Y-%m-%dT%H:%M:%S') time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
offset = date.tzinfo.utcoffset(date) offset = date.tzinfo.utcoffset(date)
Expand All @@ -64,7 +69,7 @@ def get_tag_uri(url, date):


d = '' d = ''
if date is not None: if date is not None:
d = ',%s' % date.strftime('%Y-%m-%d') d = ',%s' % datetime_safe.new_datetime(date).strftime('%Y-%m-%d')
return u'tag:%s%s:%s/%s' % (hostname, d, path, fragment) return u'tag:%s%s:%s/%s' % (hostname, d, path, fragment)


class SyndicationFeed(object): class SyndicationFeed(object):
Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/syndication/fixtures/feeddata.json
Expand Up @@ -4,7 +4,7 @@
"pk": 1, "pk": 1,
"fields": { "fields": {
"title": "My first entry", "title": "My first entry",
"date": "2008-01-01 12:30:00" "date": "1850-01-01 12:30:00"
} }
}, },
{ {
Expand Down

0 comments on commit 89c03dc

Please sign in to comment.