0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-26 02:08:31 +00:00
alerta_alerta/alerta/common/utils.py
2013-03-03 20:22:09 +00:00

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)