Author: russellm
Date: 2010-03-15 10:25:39 -0500 (Mon, 15 Mar 2010)
New Revision: 12791
Modified:
django/trunk/django/contrib/syndication/views.py
django/trunk/tests/regressiontests/syndication/tests.py
Log:
Fixed #12998 -- Corrected handling of time zones in syndication framework.
Modified: django/trunk/django/contrib/syndication/views.py
===================================================================
--- django/trunk/django/contrib/syndication/views.py 2010-03-15 13:15:01 UTC
(rev 12790)
+++ django/trunk/django/contrib/syndication/views.py 2010-03-15 15:25:39 UTC
(rev 12791)
@@ -158,22 +158,9 @@
pubdate = self.__get_dynamic_attr('item_pubdate', item)
if pubdate and not pubdate.tzinfo:
- now = datetime.datetime.now()
- utcnow = datetime.datetime.utcnow()
+ ltz = tzinfo.LocalTimezone(pubdate)
+ pubdate = pubdate.replace(tzinfo=ltz)
- # Must always subtract smaller time from larger time here.
- if utcnow > now:
- sign = -1
- tzDifference = (utcnow - now)
- else:
- sign = 1
- tzDifference = (now - utcnow)
-
- # Round the timezone offset to the nearest half hour.
- tzOffsetMinutes = sign * ((tzDifference.seconds / 60 + 15) /
30) * 30
- tzOffset = datetime.timedelta(minutes=tzOffsetMinutes)
- pubdate = pubdate.replace(tzinfo=tzinfo.FixedOffset(tzOffset))
-
feed.add_item(
title = title,
link = link,
Modified: django/trunk/tests/regressiontests/syndication/tests.py
===================================================================
--- django/trunk/tests/regressiontests/syndication/tests.py 2010-03-15
13:15:01 UTC (rev 12790)
+++ django/trunk/tests/regressiontests/syndication/tests.py 2010-03-15
15:25:39 UTC (rev 12791)
@@ -3,6 +3,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.utils import tzinfo
+from django.utils.feedgenerator import rfc2822_date, rfc3339_date
from models import Entry
from xml.dom import minidom
@@ -55,13 +56,19 @@
chan_elem = feed.getElementsByTagName('channel')
self.assertEqual(len(chan_elem), 1)
chan = chan_elem[0]
+
+ # Find the last build date
+ d = Entry.objects.latest('date').date
+ ltz = tzinfo.LocalTimezone(d)
+ last_build_date = rfc2822_date(d.replace(tzinfo=ltz))
+
self.assertChildNodes(chan, ['title', 'link', 'description',
'language', 'lastBuildDate', 'item', 'atom:link', 'ttl', 'copyright',
'category'])
self.assertChildNodeContent(chan, {
'title': 'My blog',
'description': 'A more thorough description of my blog.',
'link': 'http://example.com/blog/',
'language': 'en',
- 'lastBuildDate': 'Thu, 03 Jan 2008 13:30:00 -0600',
+ 'lastBuildDate': last_build_date,
#'atom:link': '',
'ttl': '600',
'copyright': 'Copyright (c) 2007, Sally Smith',
@@ -80,6 +87,11 @@
'http://example.com/syndication/rss2/'
)
+ # Find the pubdate of the first feed item
+ d = Entry.objects.get(pk=1).date
+ ltz = tzinfo.LocalTimezone(d)
+ pub_date = rfc2822_date(d.replace(tzinfo=ltz))
+
items = chan.getElementsByTagName('item')
self.assertEqual(len(items), Entry.objects.count())
self.assertChildNodeContent(items[0], {
@@ -87,7 +99,7 @@
'description': 'Overridden description: My first entry',
'link': 'http://example.com/blog/1/',
'guid': 'http://example.com/blog/1/',
- 'pubDate': 'Tue, 01 Jan 2008 12:30:00 -0600',
+ 'pubDate': pub_date,
'author': '[email protected] (Sally Smith)',
})
self.assertCategories(items[0], ['python', 'testing']);
@@ -198,10 +210,13 @@
response = self.client.get('/syndication/naive-dates/')
doc = minidom.parseString(response.content)
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
- tz = tzinfo.LocalTimezone(datetime.datetime.now())
- now = datetime.datetime.now(tz)
- self.assertEqual(updated[-6:], str(now)[-6:])
+ d = Entry.objects.latest('date').date
+ ltz = tzinfo.LocalTimezone(d)
+ latest = rfc3339_date(d.replace(tzinfo=ltz))
+
+ self.assertEqual(updated, latest)
+
def test_aware_datetime_conversion(self):
"""
Test that datetimes with timezones don't get trodden on.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.