Skip to content

Commit

Permalink
fix to_datetime to work with most github timestamps (converting them …
Browse files Browse the repository at this point in the history
…to UTC), don't try to remove dupes via a set (will find another way later)
  • Loading branch information
jmoiron committed Feb 14, 2011
1 parent 8a019a2 commit 4bce754
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions github/core.py
Expand Up @@ -8,6 +8,7 @@
from urllib2 import Request, urlopen
from urllib import urlencode
from functools import wraps
import re
import datetime
import time

Expand Down Expand Up @@ -66,7 +67,7 @@ def wrapper(self, **kwargs):
result = method(self, **kwargs)
except:
break
return list(set(items))
return items
return method(self, **kwargs)
return wrapper

Expand All @@ -83,8 +84,22 @@ def smart_encode(**kwargs):

def to_datetime(timestring):
"""Convert one of the bitbucket API's timestamps to a datetime object."""
format = '%Y-%m-%d %H:%M:%S'
return datetime.datetime(*time.strptime(timestring, format)[:7])
import pytz
mountain = re.search('-07:?00', timestring)
stripped = re.sub('-0\d:?00', '', timestring).strip()
try:
dt = datetime.datetime(*time.strptime(stripped, github_date_format)[:6])
except ValueError:
try:
dt = datetime.datetime(*time.strptime(stripped, commit_date_format)[:6])
except ValueError:
raise Exception("Unrecognized timestamp format for string \"%s\"" % timestring)
if mountain:
timezone = pytz.timezone('US/Mountain')
else:
timezone = pytz.timezone('US/Pacific')
local = timezone.normalize(timezone.localize(dt))
return local.astimezone(pytz.utc)

class Github(object):
"""Main github class. Use an instantiated version of this class
Expand Down

0 comments on commit 4bce754

Please sign in to comment.