Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14132 -- Fixed feedgenerator to support years < 1900. Thanks, mk.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15503 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bc5c2537ae3d09d3b9145beb027ff9f60eac6ba3 1 parent 47b1a8e
Jannis Leidel authored February 12, 2011
8  django/utils/feedgenerator.py
@@ -27,13 +27,15 @@
27 27
 import urlparse
28 28
 from django.utils.xmlutils import SimplerXMLGenerator
29 29
 from django.utils.encoding import force_unicode, iri_to_uri
  30
+from django.utils import datetime_safe
30 31
 
31 32
 def rfc2822_date(date):
32 33
     # We can't use strftime() because it produces locale-dependant results, so
33 34
     # we have to map english month and day names manually
34 35
     months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
35 36
     days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
36  
-
  37
+    # Support datetime objects older than 1900
  38
+    date = datetime_safe.new_datetime(date)
37 39
     # We do this ourselves to be timezone aware, email.Utils is not tz aware.
38 40
     dow = days[date.weekday()]
39 41
     month = months[date.month - 1]
@@ -47,6 +49,8 @@ def rfc2822_date(date):
47 49
         return time_str + '-0000'
48 50
 
49 51
 def rfc3339_date(date):
  52
+    # Support datetime objects older than 1900
  53
+    date = datetime_safe.new_datetime(date)
50 54
     if date.tzinfo:
51 55
         time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
52 56
         offset = date.tzinfo.utcoffset(date)
@@ -71,7 +75,7 @@ def get_tag_uri(url, date):
71 75
 
72 76
     d = ''
73 77
     if date is not None:
74  
-        d = ',%s' % date.strftime('%Y-%m-%d')
  78
+        d = ',%s' % datetime_safe.new_datetime(date).strftime('%Y-%m-%d')
75 79
     return u'tag:%s%s:%s/%s' % (hostname, d, path, fragment)
76 80
 
77 81
 class SyndicationFeed(object):
2  tests/regressiontests/syndication/fixtures/feeddata.json
@@ -4,7 +4,7 @@
4 4
     "pk": 1,
5 5
     "fields": {
6 6
       "title": "My first entry",
7  
-      "date": "2008-01-01 12:30:00"
  7
+      "date": "1850-01-01 12:30:00"
8 8
     }
9 9
   },
10 10
   {

0 notes on commit bc5c253

Please sign in to comment.
Something went wrong with that request. Please try again.