mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-19 07:53:00 +00:00
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:
@@ -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'
|
||||
|
Reference in New Issue
Block a user