- Avoid changing locale to parse timestamps.
- Use emails RFC 2822 parser.
- Added a test.
#! /usr/bin/env bash
if [[ $TRAVIS_SECURE_ENV_VARS == "false" ]]; then
- USE_REPLAY=1 nosetests -v tests.test_api
+ USE_REPLAY=1 nosetests -v tests.test_api tests.test_utils
else
- nosetests -v tests.test_api tests.test_streaming tests.test_cursors
+ nosetests -v tests.test_api tests.test_streaming tests.test_cursors tests.test_utils
fi
--- /dev/null
+from unittest import TestCase
+
+from tweepy.utils import *
+
+class TweepyUtilsTests(TestCase):
+
+ def testparse_datetime(self):
+ result = parse_datetime("Wed Aug 27 13:08:45 +0000 2008")
+ self.assertEqual(datetime(2008, 8, 27, 13, 8, 45), result)
+
import re
import locale
from urllib import quote
+from email.utils import parsedate
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
- 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
-
+ return datetime(*(parsedate(string)[:6]))
def parse_html_value(html):