Handle naive datetimes gracefully

This commit is contained in:
Brian Tiemann 2024-08-26 11:27:29 -04:00
parent 07ad4c1c9c
commit 409564091d

View File

@ -219,7 +219,8 @@ def isodate(value):
text = value.isoformat()
return mark_safe(f'<span title="{naturalday(value)}">{text}</span>')
elif type(value) is datetime.datetime:
text = localtime(value).date().isoformat()
local_value = localtime(value) if value.tzinfo else value
text = local_value.date().isoformat()
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
else:
return ''
@ -230,7 +231,8 @@ def isotime(value, spec='seconds'):
if type(value) is datetime.time:
return value.isoformat(timespec=spec)
if type(value) is datetime.datetime:
return localtime(value).time().isoformat(timespec=spec)
local_value = localtime(value) if value.tzinfo else value
return local_value.time().isoformat(timespec=spec)
return ''