Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26653 closed Cleanup/optimization (fixed)

Make syndication's lastBuildDate timezone aware

Reported by: didrix Owned by: Ketan Bhatt
Component: contrib.syndication Version: 1.9
Severity: Normal Keywords: timezone syndication lastBuildDate
Cc: berker.peksag@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The lastBuildDate element in an RSS feed is not timezone aware. For instance on a non-utc timezone ('Europe/Amsterdam') it will generate a response with

<lastBuildDate>Mon, 23 May 2016 11:36:39 -0000</lastBuildDate>

while it should be

<lastBuildDate>Mon, 23 May 2016 11:36:39 +0200</lastBuildDate>

relevant files:
django/utils/feedgenerator.py

Seen in version 1.9.6 and 1.10a1, probably more versions affected.
pytz._version_ = 2016.4

Change History (9)

comment:1 by Tim Graham, 8 years ago

Easy pickings: set
Has patch: set
Needs tests: set
Summary: Syndication's lastBuildDate is not timezone aware.Make syndication's lastBuildDate timezone aware
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

I guess a patch might look like:

  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index 3a91af3..2bbc7b8 100644
    a b from __future__ import unicode_literals  
    2626import datetime
    2727import warnings
    2828
    29 from django.utils import datetime_safe, six
     29from django.utils import datetime_safe, six, timezone
    3030from django.utils.deprecation import RemovedInDjango20Warning
    3131from django.utils.encoding import force_text, iri_to_uri
    3232from django.utils.six import StringIO
    class SyndicationFeed(object):  
    223223                    if latest_date is None or item_date > latest_date:
    224224                        latest_date = item_date
    225225
    226         return latest_date or datetime.datetime.now()
     226        return latest_date or timezone.now()
    227227
    228228
    229229class Enclosure(object):

in reply to:  1 comment:2 by didrix, 8 years ago

Replying to timgraham:

I guess a patch might look like:

  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index 3a91af3..2bbc7b8 100644
    a b class SyndicationFeed(object):  
    226         return latest_date or datetime.datetime.now()
     226        return latest_date or timezone.now()

Could also do this:

  • django/utils/feedgenerator.py

    diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py
    index 3a91af3..2bbc7b8 100644
    a b class SyndicationFeed(object):  
    226         return latest_date or datetime.datetime.now()
     226        return latest_date or timezone.localtime(timezone.now())

What do you reckon?

comment:3 by Aymeric Augustin, 8 years ago

Let's use UTC.

comment:4 by Ketan Bhatt, 8 years ago

Owner: changed from nobody to Ketan Bhatt
Status: newassigned

comment:5 by Ketan Bhatt, 8 years ago

Hey,

This is the first time I am contributing to Django, so please help me if I do some mistakes.

I followed the steps from this guideline https://docs.djangoproject.com/en/1.9/internals/contributing/writing-code/working-with-git/

Here is the link to the branch I have done my changes on: https://github.com/ketanbhatt/django/tree/ticket_26653

And here is the PR: https://github.com/django/django/pull/6648

Please take a look and let me know the next steps.

Thank you

Last edited 8 years ago by Ketan Bhatt (previous) (diff)

comment:6 by Berker Peksag, 8 years ago

Cc: berker.peksag@… added
Needs tests: unset
Patch needs improvement: set

comment:7 by Berker Peksag, 8 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

PR #6648 looks good to me.

comment:8 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In f31fbba:

Fixed #26653 -- Made SyndicationFeed.latest_post_date() return time in UTC.

comment:9 by Tim Graham <timograham@…>, 8 years ago

In 37aec6b1:

Refs #26653 -- Fixed a feedgenerator test that requires a database query on PostgreSQL.

Note: See TracTickets for help on using tickets.
Back to Top