Skip to content

Commit c6c972d

Browse files
committed
Fix various get_datetime errors
1 parent d4ef8f5 commit c6c972d

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

brawlstats/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ def bstag(tag):
4444
return tag
4545

4646

47-
def get_datetime(timestamp: str, unix: bool=True) -> Union[int, datetime.datetime]:
47+
def get_datetime(timestamp: str, unix: bool=True) -> Union[int, datetime]:
4848
"""Converts a %Y%m%dT%H%M%S.%fZ to a UNIX timestamp or a datetime.datetime object
4949
5050
Parameters
5151
----------
5252
timestamp : str
53-
A timestamp in the %Y-%m-%dT%H:%M:%S.%fZ format, usually returned by the API
54-
in the ``created_time`` field for example (eg. 2018-07-18T14:59:06.000Z)
53+
A timestamp in the %Y%%dT%H%M%S.%fZ format, usually returned by the API in the
54+
``battleTime`` field in battle log responses - e.g., 20200925T184431.000Z
5555
unix : bool, optional
5656
Whether to return a POSIX timestamp (seconds since epoch) or not, by default True
5757
@@ -60,11 +60,12 @@ def get_datetime(timestamp: str, unix: bool=True) -> Union[int, datetime.datetim
6060
Union[int, datetime.datetime]
6161
If unix=True it will return int, otherwise datetime.datetime
6262
"""
63-
time = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')
63+
time = datetime.strptime(timestamp, '%Y%m%dT%H%M%S.%fZ')
64+
6465
if unix:
6566
return int(time.timestamp())
66-
else:
67-
return time
67+
68+
return time
6869

6970

7071
def nothing(value):

0 commit comments

Comments
 (0)