allow isoformat(None)

simplifies "if timestamp is None" cases when we are just using it to serialize nullable timestamps to JSON
This commit is contained in:
Min RK
2018-04-05 11:31:17 +02:00
parent 6f8a34127b
commit 31d3f7a20b
2 changed files with 6 additions and 13 deletions

View File

@@ -45,6 +45,10 @@ def isoformat(dt):
Naïve datetime objects are assumed to be UTC
"""
# allow null timestamps to remain None without
# having to check if isoformat should be called
if dt is None:
return None
if dt.tzinfo:
dt = dt.astimezone(timezone.utc).replace(tzinfo=None)
return dt.isoformat() + 'Z'