allow times without microseconds

This commit is contained in:
Kyle Robbertze 2021-06-04 20:01:17 +02:00
parent 280091bfd7
commit a1bf8c8c44
2 changed files with 5 additions and 1 deletions

View File

@ -198,5 +198,8 @@ def fromisoformat(time_string):
only added in Python 3.7. Until LibreTime drops Python 3.6 support, this only added in Python 3.7. Until LibreTime drops Python 3.6 support, this
wrapper uses the old way of doing it. wrapper uses the old way of doing it.
""" """
try:
datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S.%f") datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S.%f")
except ValueError:
datetime_obj = datetime.datetime.strptime(time_string, "%H:%M:%S")
return datetime_obj.time() return datetime_obj.time()

View File

@ -51,6 +51,7 @@ def test_get_protocol_force_https(payload, use_config, values, expected):
[ [
("00:00:00.500000", datetime.time(microsecond=500000)), ("00:00:00.500000", datetime.time(microsecond=500000)),
("00:04:30.092540", datetime.time(minute=4, second=30, microsecond=92540)), ("00:04:30.092540", datetime.time(minute=4, second=30, microsecond=92540)),
("00:04:30", datetime.time(minute=4, second=30)),
], ],
) )
def test_fromisoformat(payload, expected): def test_fromisoformat(payload, expected):