summaryrefslogtreecommitdiff
path: root/django/utils/feedgenerator.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-05 17:38:49 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-05 17:38:49 +0000
commit34008aaeb0fc62d782735ff62c745a658888521e (patch)
treeae519b39a06040a0d04d903ad0100f783f02ae1d /django/utils/feedgenerator.py
parent8e24b3761084618fa259f6499b1a9110d19a28c2 (diff)
Fixed #7016: use correct time zones for Atom feeds. Thanks, Chris Cahoon.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8216 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/feedgenerator.py')
-rw-r--r--django/utils/feedgenerator.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
index 23400bb8e7..ce09c4fc27 100644
--- a/django/utils/feedgenerator.py
+++ b/django/utils/feedgenerator.py
@@ -22,14 +22,25 @@ http://diveintomark.org/archives/2004/02/04/incompatible-rss
from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_unicode, iri_to_uri
import datetime, re, time
-import email.Utils
def rfc2822_date(date):
- return email.Utils.formatdate(time.mktime(date.timetuple()))
+ # We do this ourselves to be timezone aware, email.Utils is not tz aware.
+ if date.tzinfo:
+ time_str = date.strftime('%a, %d %b %Y %H:%M:%S ')
+ offset = date.tzinfo.utcoffset(date)
+ timezone = (offset.days * 24 * 60) + (offset.seconds / 60)
+ hour, minute = divmod(timezone, 60)
+ return time_str + "%+03d%02d" % (hour, minute)
+ else:
+ return date.strftime('%a, %d %b %Y %H:%M:%S -0000')
def rfc3339_date(date):
if date.tzinfo:
- return date.strftime('%Y-%m-%dT%H:%M:%S%z')
+ time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
+ offset = date.tzinfo.utcoffset(date)
+ timezone = (offset.days * 24 * 60) + (offset.seconds / 60)
+ hour, minute = divmod(timezone, 60)
+ return time_str + "%+03d:%02d" % (hour, minute)
else:
return date.strftime('%Y-%m-%dT%H:%M:%SZ')