Skip to content

Commit

Permalink
Merge pull request #14 from dga-nagra/fix_ha_info
Browse files Browse the repository at this point in the history
Adding edge-case for datetime serialization
  • Loading branch information
divad1196 authored Sep 24, 2024
2 parents 4cfa8c0 + ecd4fd5 commit 1d21774
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pa_api/xmlapi/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from pa_api.utils import first
from pa_api.xmlapi.utils import el2dict

DATETIME_FORMAT = "%Y/%m/%d %H:%M:%S"
TIME_FORMAT = "%H:%M:%S"
DATETIME_FORMAT = f"%Y/%m/%d {TIME_FORMAT}"
DATETIME_MS_FORMAT = f"{DATETIME_FORMAT}.%f"
NoneType: type = type(None)


Expand All @@ -31,11 +32,14 @@ def parse_datetime(d):
try:
if d is None or d in ("none", "Unknown"):
return None
return datetime.strptime(d, DATETIME_FORMAT)
try:
return datetime.strptime(d, DATETIME_FORMAT)
except Exception:
return datetime.strptime(d, DATETIME_MS_FORMAT)
except Exception as e:
logging.debug(e)
logging.debug(f"Failed to parse {d} as datetime")
print(d, type(d))
# print(d, type(d))
raise
return d

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pa-api-sdk"
version = "0.1.5"
version = "0.1.6"
description = ""
authors = ["David Gallay <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 1d21774

Please sign in to comment.