# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return


from datetime import datetime, timedelta
from alertaclient.utils import DateTime

    @property
    def latency(self):
        return int((self.receive_time - self.create_time).total_seconds() * 1000)

    @property
    def since(self):
        since = datetime.utcnow() - self.receive_time
        return since - timedelta(microseconds=since.microseconds)

    def __repr__(self):
        return 'Heartbeat(id={!r}, origin={!r}, create_time={!r}, timeout={!r}, customer={!r})'.format(
            self.id, self.origin, self.create_time, self.timeout, self.customer)

    @classmethod
    def parse(cls, json):
        if not isinstance(json.get('tags', []), list):
            raise ValueError('tags must be a list')
        if not isinstance(json.get('attributes', {}), dict):
            raise ValueError('attributes must be a JSON object')
        if not isinstance(json.get('timeout', 0), int):
            raise ValueError('timeout must be an integer')

        return Heartbeat(
            id=json.get('id', None),
            origin=json.get('origin', None),
            status=json.get('status', None),
            tags=json.get('tags', list()),
            attributes=json.get('attributes', dict()),
            event_type=json.get('type', None),

# Path: alertaclient/utils.py
# class DateTime:
#     @staticmethod
#     def parse(date_str):
#         if not isinstance(date_str, str):
#             return
#         try:
#             return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ')
#         except Exception:
#             raise ValueError('dates must be ISO 8601 date format YYYY-MM-DDThh:mm:ss.sssZ')
# 
#     @staticmethod
#     def iso8601(dt):
#         return dt.replace(microsecond=0).strftime('%Y-%m-%dT%H:%M:%S') + '.%03dZ' % (dt.microsecond // 1000)
# 
#     @staticmethod
#     def localtime(dt, timezone=None, fmt='%Y/%m/%d %H:%M:%S'):
#         tz = pytz.timezone(timezone)
#         try:
#             return dt.replace(tzinfo=pytz.UTC).astimezone(tz).strftime(fmt)
#         except AttributeError:
#             return


# Path: alertaclient/models/heartbeat.py
from datetime import datetime, timedelta
from alertaclient.utils import DateTime


    @property
    def latency(self):
        return int((self.receive_time - self.create_time).total_seconds() * 1000)

    @property
    def since(self):
        since = datetime.utcnow() - self.receive_time
        return since - timedelta(microseconds=since.microseconds)

    def __repr__(self):
        return 'Heartbeat(id={!r}, origin={!r}, create_time={!r}, timeout={!r}, customer={!r})'.format(
            self.id, self.origin, self.create_time, self.timeout, self.customer)

    @classmethod
    def parse(cls, json):
        if not isinstance(json.get('tags', []), list):
            raise ValueError('tags must be a list')
        if not isinstance(json.get('attributes', {}), dict):
            raise ValueError('attributes must be a JSON object')
        if not isinstance(json.get('timeout', 0), int):
            raise ValueError('timeout must be an integer')

        return Heartbeat(
            id=json.get('id', None),
            origin=json.get('origin', None),
            status=json.get('status', None),
            tags=json.get('tags', list()),
            attributes=json.get('attributes', dict()),
            event_type=json.get('type', None),

            create_time=DateTime.parse(json.get('createTime')),