From f31fbbae1ab1572e1637fc5ca9ae4bae66679294 Mon Sep 17 00:00:00 2001 From: Ketan Bhatt Date: Tue, 24 May 2016 22:20:20 +0530 Subject: Fixed #26653 -- Made SyndicationFeed.latest_post_date() return time in UTC. --- django/utils/feedgenerator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'django/utils') diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 3a91af3815..aeb054f4e9 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -31,6 +31,7 @@ from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text, iri_to_uri from django.utils.six import StringIO from django.utils.six.moves.urllib.parse import urlparse +from django.utils.timezone import utc from django.utils.xmlutils import SimplerXMLGenerator @@ -211,7 +212,7 @@ class SyndicationFeed(object): def latest_post_date(self): """ Returns the latest item's pubdate or updateddate. If no items - have either of these attributes this returns the current date/time. + have either of these attributes this returns the current UTC date/time. """ latest_date = None date_keys = ('updateddate', 'pubdate') @@ -223,7 +224,8 @@ class SyndicationFeed(object): if latest_date is None or item_date > latest_date: latest_date = item_date - return latest_date or datetime.datetime.now() + # datetime.now(tz=utc) is slower, as documented in django.utils.timezone.now + return latest_date or datetime.datetime.utcnow().replace(tzinfo=utc) class Enclosure(object): -- cgit v1.3