views:

132

answers:

1

I'm trying to parse a twitter feed in django, and I'm having a strange problem converting the published time:

I've got the time from the feed into a full 9-tuple correctly:

>> print tweet_time
time.struct_time(tm_year=2009, tm_mon=6, tm_mday=17, tm_hour=14, tm_min=35, tm_sec=28, tm_wday=2, tm_yday=168, tm_isdst=0)

But when I call this:

tweet_time = datetime.fromtimestamp(time.mktime(tweet_time))

I end up with the a time 1 hour ahead:

>> print tweet_time
2009-06-17 15:35:28

What am I missing here?

+4  A: 

try flipping the isdst (is daylight savings flag) to a -1 and see if that fixes it. -1 tells it to use (guess) the local daylight savings setting and roll with that.

whatsisname
Your suggestion was right, though some hint of how to do that would've been helpful. The working code is this:tweet_time = datetime.fromtimestamp(time.mktime(tweet_time[0:8] + (-1,)))All that trouble for a bad DST flag. Grr.
Gabriel Hurley
This reminds that you should use UTC internally and convert it to local time for output only (like display). Pytz to the rescue.
zgoda