Ticket #10447: rfc2822_date.patch

File rfc2822_date.patch, 1.3 KB (added by lupus, 15 years ago)

rfc2822_date patch

  • feedgenerator.py

     
    2525from django.utils.encoding import force_unicode, iri_to_uri
    2626
    2727def rfc2822_date(date):
     28    # We can't use strftime() because it produces locale-dependant results, so we have to map english month and day names manually
     29    months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
     30    days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',)
     31
    2832    # We do this ourselves to be timezone aware, email.Utils is not tz aware.
    2933    if date.tzinfo:
    30         time_str = date.strftime('%a, %d %b %Y %H:%M:%S ')
     34        time_str = date.strftime(days[date.weekday()] + ', %d ' + months[date.month - 1] + ' %Y %H:%M:%S ')
    3135        offset = date.tzinfo.utcoffset(date)
    3236        timezone = (offset.days * 24 * 60) + (offset.seconds / 60)
    3337        hour, minute = divmod(timezone, 60)
    3438        return time_str + "%+03d%02d" % (hour, minute)
    3539    else:
    36         return date.strftime('%a, %d %b %Y %H:%M:%S -0000')
     40        time_str = date.strftime(days[date.weekday()] + ', %d ' + months[date.month - 1] + ' %Y %H:%M:%S  -0000')
     41        return time_str
    3742
    3843def rfc3339_date(date):
    3944    if date.tzinfo:
Back to Top