Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:38:49 (5 months ago)
Author:
jacob
Message:

Fixed #7016: use correct time zones for Atom feeds. Thanks, Chris Cahoon.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/feedgenerator.py

    r7066 r8216  
    2323from django.utils.encoding import force_unicode, iri_to_uri 
    2424import datetime, re, time 
    25 import email.Utils 
    2625 
    2726def rfc2822_date(date): 
    28     return email.Utils.formatdate(time.mktime(date.timetuple())) 
     27    # We do this ourselves to be timezone aware, email.Utils is not tz aware. 
     28    if date.tzinfo: 
     29        time_str = date.strftime('%a, %d %b %Y %H:%M:%S ') 
     30        offset = date.tzinfo.utcoffset(date) 
     31        timezone = (offset.days * 24 * 60) + (offset.seconds / 60) 
     32        hour, minute = divmod(timezone, 60) 
     33        return time_str + "%+03d%02d" % (hour, minute) 
     34    else: 
     35        return date.strftime('%a, %d %b %Y %H:%M:%S -0000') 
    2936 
    3037def rfc3339_date(date): 
    3138    if date.tzinfo: 
    32         return date.strftime('%Y-%m-%dT%H:%M:%S%z') 
     39        time_str = date.strftime('%Y-%m-%dT%H:%M:%S') 
     40        offset = date.tzinfo.utcoffset(date) 
     41        timezone = (offset.days * 24 * 60) + (offset.seconds / 60) 
     42        hour, minute = divmod(timezone, 60) 
     43        return time_str + "%+03d:%02d" % (hour, minute) 
    3344    else: 
    3445        return date.strftime('%Y-%m-%dT%H:%M:%SZ')