From f7b96f3ffe7240e4f9935a2c6e6ef1cba0c77665 Mon Sep 17 00:00:00 2001 From: Ivo Wetzel Date: Fri, 12 Mar 2010 16:28:54 -0600 Subject: [PATCH] Fix an issue with locale parsing dates. Fixes issue #13 --- tweepy/utils.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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): -- 2.25.1