mirror of
https://github.com/alerta/alerta.git
synced 2025-01-26 02:08:31 +00:00
14 lines
420 B
Python
14 lines
420 B
Python
"""Utilities and helper functions."""
|
|
|
|
import json
|
|
import datetime
|
|
|
|
|
|
# Extend JSON Encoder to support ISO 8601 format dates
|
|
class DateEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
|
|
if isinstance(obj, (datetime.date, datetime.datetime)):
|
|
return obj.replace(microsecond=0).isoformat() + ".%03dZ" % (obj.microsecond // 1000)
|
|
else:
|
|
return json.JSONEncoder.default(self, obj)
|