Skip to content
Snippets Groups Projects
Commit 77d8cb4d authored by florian's avatar florian
Browse files

FIX: Compare datetime treats timezones and milliseconds

parent ce3e5365
No related branches found
No related tags found
1 merge request!22Release 0.3
......@@ -594,7 +594,31 @@ def assure_has_property(entity, name, value, to_be_updated=None,
if isinstance(value, datetime):
if datetime.fromisoformat(el.value) == value:
try:
compare_time = datetime.fromisoformat(el.value)
except ValueError:
# special case of wrong iso format
# time zone
tmp = el.value.split("+")
if len(tmp) == 2:
tz_str = '+' + tmp[1][:2] + ':' + tmp[1][2:]
else:
tz_str = ""
tmp = tmp[0]
# milli- and micrseconds
tmp = tmp.split(".")
if len(tmp) == 2:
if len(tmp[1]) < 6:
ms = '.' + tmp[1] + '0'*(6-len(tmp[1]))
else:
raise ValueError(
"invalid millisecond format in {}".format(el.value))
else:
ms = ""
tmp = tmp[0] + ms + tz_str
compare_time = datetime.fromisoformat(tmp)
if compare_time == value:
contained = True
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment