Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved date parsing (locale problems + the fix) follow up to issue 10 #24

Closed
GoogleCodeExporter opened this issue Nov 19, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

in reference to: http://code.google.com/p/python-twitter/issues/detail?id=10

Sorry for the confusion, but the current way to parse the date does not
work with alternate locale settings.

calendar.timegm(time.strptime(self.created_at, '%a %b %d %H:%M:%S +0000 %Y'))

Since twitter appears to be using rfc822 dates, parse them as such:

import rfc822
calendar.timegm(rfc822.parsedate(self.created_at))

Example of the problem:

>>> import time
>>> mytime = time.strftime('%a %b %d %H:%M:%S +0000 %Y')
>>> time.strptime(mytime, '%a %b %d %H:%M:%S +0000 %Y')
(2008, 8, 8, 13, 22, 37, 4, 221, -1)
>>> import locale
>>> locale.setlocale(locale.LC_ALL, ('Russian_Russia', '1251'))
'Russian_Russia.1251'
>>> time.strptime(mytime, '%a %b %d %H:%M:%S +0000 %Y')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "python\lib\_strptime.py", line 330, in strptime
    (data_string, format))
ValueError: time data did not match format:  data=Fri Aug 08 13:22:37 +0000
2008 
fmt=%a %b %d %H:%M:%S +0000 %Y
>>> import rfc822
>>> rfc822.parsedate(mytime)
(2008, 8, 8, 13, 22, 37, 0, 1, 0)


Original issue reported on code.google.com by Stelmina...@gmail.com on 14 Aug 2008 at 11:09

@GoogleCodeExporter
Copy link
Author

Original comment by dclinton on 9 Sep 2008 at 4:05

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Finally fixed this in trunk in r131
(http://code.google.com/p/python-twitter/source/detail?r=131).  Please verify.

Original comment by dclinton on 21 Feb 2009 at 5:28

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

"passdate" was wrong, should have been "parsedate"

I'm sorry, not sure how I managed that typo.

Original comment by Stelmina...@gmail.com on 21 Feb 2009 at 11:52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant