Skip to content

Commit b273037

Browse files
committed
Add dateutil to parse timestamps
GitHub is inconsistent in the timestamps it returns for the issue import API. strptime has a way of handling UTC offsets a format like -0600 but not -06:00. There's no good way to handle that with the standard library, so here we must add dateutil.
1 parent 232cff2 commit b273037

File tree

3 files changed

+7
-27
lines changed

3 files changed

+7
-27
lines changed

github3/models.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
"""This module provides the basic models used in github3.py."""
33
from __future__ import unicode_literals
44

5-
from datetime import datetime
65
from json import dumps, loads
76
from logging import getLogger
87

8+
import dateutil.parser
99
import requests
1010
from requests.compat import is_py2, urlparse
1111

1212
from . import exceptions
1313
from .session import GitHubSession
14-
from .utils import UTC
1514

16-
__timeformat__ = '%Y-%m-%dT%H:%M:%SZ'
1715
__logs__ = getLogger(__package__)
1816

1917

@@ -145,9 +143,7 @@ def _strptime(cls, time_str):
145143
:rtype: datetime or None
146144
"""
147145
if time_str:
148-
# Parse UTC string into naive datetime, then add timezone
149-
dt = datetime.strptime(time_str, __timeformat__)
150-
return dt.replace(tzinfo=UTC())
146+
return dateutil.parser.parse(time_str)
151147
return None
152148

153149
def __repr__(self):

github3/utils.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,6 @@ def timestamp_parameter(timestamp, allow_none=True):
4545
raise ValueError("Cannot accept type %s for timestamp" % type(timestamp))
4646

4747

48-
class UTC(datetime.tzinfo):
49-
50-
"""Yet another UTC reimplementation, to avoid a dependency on pytz or
51-
dateutil."""
52-
53-
ZERO = datetime.timedelta(0)
54-
55-
def __repr__(self):
56-
return 'UTC()'
57-
58-
def dst(self, dt):
59-
return self.ZERO
60-
61-
def tzname(self, dt):
62-
return 'UTC'
63-
64-
def utcoffset(self, dt):
65-
return self.ZERO
66-
67-
6848
def stream_response_to_file(response, path=None):
6949
"""Stream a response body to the specified file.
7050

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
os.system("python setup.py bdist_wheel sdist upload")
3535
sys.exit()
3636

37-
requires.extend(["requests >= 2.18", "uritemplate >= 3.0.0"])
37+
requires.extend([
38+
"requests >= 2.18",
39+
"uritemplate >= 3.0.0",
40+
"python-dateutil >= 2.6.0",
41+
])
3842

3943
__version__ = ''
4044
with open('github3/__about__.py', 'r') as fd:

0 commit comments

Comments
 (0)