Skip to content

Commit 5746320

Browse files
committed
fix: fix parse_timestamp for Python <= 3.10
1 parent a1621c0 commit 5746320

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

topgg/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
# SPDX-License-Identifier: MIT
2+
# SPDX-FileCopyrightText: 2026 null8626 & Top.gg
3+
14
from datetime import datetime
25
from sys import version_info
36

47

5-
if version_info.major == 3 and version_info.minor <= 10:
8+
if version_info.major == 3 and version_info.minor <= 10: # pragma: nocover
69
from re import compile
710

8-
TIMESTAMP_MILLISECOND_FIX_REGEX = compile(r'\.(\d+)')
9-
TIMESTAMP_MILLISECOND_FIX_TRIMMER = lambda match: match.group(1)[:3]
11+
TIMESTAMP_MILLISECOND_FIX_REGEX = compile(r'\.(\d{4,})')
12+
TIMESTAMP_MILLISECOND_FIX_TRIMMER = lambda match: f'.{match.group(1)[:3]}'
1013

1114

1215
def parse_timestamp(timestamp: str) -> datetime:
1316
"""Parses an ISO format timestamp to a Python datetime instance."""
1417

15-
if version_info.major == 3 and version_info.minor <= 10:
18+
if version_info.major == 3 and version_info.minor <= 10: # pragma: nocover
1619
timestamp = TIMESTAMP_MILLISECOND_FIX_REGEX.sub(
1720
TIMESTAMP_MILLISECOND_FIX_TRIMMER, timestamp
1821
)

0 commit comments

Comments
 (0)