[#340] s/datetime.fromisoformat/dateutil.parser.isoparse/

We may receive JavaScript timestamps with non-standard `Z` suffix too.
This commit is contained in:
Fabio Manganiello 2023-12-11 22:24:55 +01:00
parent 6e7c5def2f
commit 6edb8c8318
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 2 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from random import randint
from typing import Callable, Optional, Union from typing import Callable, Optional, Union
import croniter import croniter
from dateutil.parser import isoparse
from dateutil.tz import gettz from dateutil.tz import gettz
from platypush.context import get_bus, get_plugin from platypush.context import get_bus, get_plugin
@ -171,7 +172,7 @@ class Alarm:
except (AttributeError, croniter.CroniterBadCronError): except (AttributeError, croniter.CroniterBadCronError):
try: try:
# If when is an ISO-8601 timestamp, parse it # If when is an ISO-8601 timestamp, parse it
t = datetime.datetime.fromisoformat(self.when).timestamp() t = isoparse(self.when).timestamp()
except Exception as e: except Exception as e:
raise AssertionError(f'Invalid alarm time {self.when}: {e}') from e raise AssertionError(f'Invalid alarm time {self.when}: {e}') from e