Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10447 -- Made sure the syndication feeds helper function that …

…returns RFC 2822-formatted datetime strings isn't affected by the current locale, removing use of strftime() because the '%a' and '%b' format specifiers are problematic in this respect. Thanks bear330 for the report and lupus for an initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8219a13092e05a85a7d5b6abf9c878f44de3444c 1 parent 9b18b46
Ramiro Morales authored December 29, 2010

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. 11  django/utils/feedgenerator.py
11  django/utils/feedgenerator.py
@@ -29,15 +29,22 @@
29 29
 from django.utils.encoding import force_unicode, iri_to_uri
30 30
 
31 31
 def rfc2822_date(date):
  32
+    # We can't use strftime() because it produces locale-dependant results, so
  33
+    # we have to map english month and day names manually
  34
+    months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
  35
+    days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
  36
+
32 37
     # We do this ourselves to be timezone aware, email.Utils is not tz aware.
  38
+    dow = days[date.weekday()]
  39
+    month = months[date.month - 1]
  40
+    time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
33 41
     if date.tzinfo:
34  
-        time_str = date.strftime('%a, %d %b %Y %H:%M:%S ')
35 42
         offset = date.tzinfo.utcoffset(date)
36 43
         timezone = (offset.days * 24 * 60) + (offset.seconds / 60)
37 44
         hour, minute = divmod(timezone, 60)
38 45
         return time_str + "%+03d%02d" % (hour, minute)
39 46
     else:
40  
-        return date.strftime('%a, %d %b %Y %H:%M:%S -0000')
  47
+        return time_str + '-0000'
41 48
 
42 49
 def rfc3339_date(date):
43 50
     if date.tzinfo:

0 notes on commit 8219a13

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