fix mid level issues. updated changelog
This commit is contained in:
@@ -87,11 +87,24 @@ class TcxParser:
|
||||
|
||||
|
||||
def _parse_ts(s: str) -> datetime:
|
||||
# ISO 8601 with or without fractional seconds
|
||||
s = s.rstrip("Z")
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
return datetime.strptime(s, fmt).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
# ISO 8601 with or without fractional seconds, with Z or numeric offset (+02:00)
|
||||
import re as _re
|
||||
# Strip trailing Z → assume UTC
|
||||
if s.endswith("Z"):
|
||||
s = s[:-1]
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
return datetime.strptime(s, fmt).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
# Numeric offset like +02:00 or -05:30 — parse with %z then convert to UTC
|
||||
m = _re.match(r"^(.+)([+-]\d{2}:\d{2})$", s)
|
||||
if m:
|
||||
body, off = m.group(1), m.group(2).replace(":", "")
|
||||
for fmt in ("%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"):
|
||||
try:
|
||||
dt = datetime.strptime(body + off, fmt + "%z")
|
||||
return dt.astimezone(timezone.utc).replace(tzinfo=timezone.utc)
|
||||
except ValueError:
|
||||
continue
|
||||
raise ValueError(f"Cannot parse timestamp: {s!r}")
|
||||
|
||||
Reference in New Issue
Block a user