libo26 / feedparser

Automatically exported from code.google.com/p/feedparser
Other
0 stars 0 forks source link

Time zones not being parsed #207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Read feed "http://feeds.reuters.com/reuters/topNews?format=xml"
2. Dump date information from both "date" and "date_parsed" fields.

What is the expected output? 

"date": "Sun, 28 Feb 2010 11:57:48 -0500"
"date_parsed": time.struct_time(tm_year=2010, tm_mon=2, tm_mday=28, tm_hour
=16, tm_min=57, tm_sec=48, tm_wday=6, tm_yday=59, tm_isdst=0)

This is correct as far as it goes, but the timezone info has been lost.

The problem is that "feedparser" is calling rfc822.parsedate, not
rfc822.parsedate_tz.  Here's a workaround:

def RFC2822dateparser(aDateString):
    """parse a RFC2822 date, including time zone: 'Sun, 28 Feb 2010
11:57:48 -0500'"""
    dateinfo = rfc822.parsedate_tz(aDateString) # parse date
    if dateinfo is None :           # if none, fail
        return(None)
    utcstamp = rfc822.mktime_tz(dateinfo)   # convert to timestamp 
    utcdate = time.gmtime(utcstamp) # cback to time tuple, but in UT
    return(utcdate)

feedparser.registerDateHandler(RFC2822dateparser)   # register above
conversion with feedparser

Original issue reported on code.google.com by na...@animats.com on 28 Feb 2010 at 6:55

GoogleCodeExporter commented 9 years ago
Can you check this with the latest version of the code:
http://code.google.com/p/feedparser/source/browse/trunk/feedparser/feedparser.py

I can't find any places where it does what you claim. 

Original comment by adewale on 28 Feb 2010 at 7:08

GoogleCodeExporter commented 9 years ago
In the distributed April 2007 version, from

http://code.google.com/p/feedparser/downloads/list

the bug exists.  In the code repository, it appears to have been fixed. 

I cannot be responsible for the failure of the developers to update their 
distribution.

Original comment by na...@animats.com on 28 Feb 2010 at 7:41

GoogleCodeExporter commented 9 years ago
Thanks. I'm closing this bug.

Original comment by adewale on 1 Mar 2010 at 6:18