From: Ivo Wetzel Date: Fri, 12 Mar 2010 22:28:54 +0000 (-0600) Subject: Fix an issue with locale parsing dates. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f7b96f3ffe7240e4f9935a2c6e6ef1cba0c77665;p=tweepy.git Fix an issue with locale parsing dates. Fixes issue #13 --- diff --git a/tweepy/utils.py b/tweepy/utils.py index 5697045..404bd86 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -6,12 +6,19 @@ from datetime import datetime import time import htmlentitydefs import re +import locale -def parse_datetime(str): +def parse_datetime(string): + # Set locale for date parsing + locale.setlocale(locale.LC_TIME, 'C') # We must parse datetime this way to work in python 2.4 - return datetime(*(time.strptime(str, '%a %b %d %H:%M:%S +0000 %Y')[0:6])) + date = datetime(*(time.strptime(string, '%a %b %d %H:%M:%S +0000 %Y')[0:6])) + + # Reset locale back to the default setting + locale.setlocale(locale.LC_TIME, '') + return date def parse_html_value(html): @@ -26,10 +33,16 @@ def parse_a_href(atag): return atag[start:end] -def parse_search_datetime(str): +def parse_search_datetime(string): + # Set locale for date parsing + locale.setlocale(locale.LC_TIME, 'C') + + # We must parse datetime this way to work in python 2.4 + date = datetime(*(time.strptime(string, '%a, %d %b %Y %H:%M:%S +0000')[0:6])) - # python 2.4 - return datetime(*(time.strptime(str, '%a, %d %b %Y %H:%M:%S +0000')[0:6])) + # Reset locale back to the default setting + locale.setlocale(locale.LC_TIME, '') + return date def unescape_html(text):