# 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
    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')),
            timeout=json.get('timeout', None),
            max_latency=json.get('maxLatency', None) or DEFAULT_MAX_LATENCY,
            receive_time=DateTime.parse(json.get('receiveTime')),
            customer=json.get('customer', None)
        )

    def tabular(self, timezone=None):
        return {
            'id': self.id,
            'origin': self.origin,
            'customer': self.customer,
            'tags': ','.join(self.tags),
            'attributes': self.attributes,
            'createTime': DateTime.localtime(self.create_time, timezone),

# 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

    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')),
            timeout=json.get('timeout', None),
            max_latency=json.get('maxLatency', None) or DEFAULT_MAX_LATENCY,
            receive_time=DateTime.parse(json.get('receiveTime')),
            customer=json.get('customer', None)
        )

    def tabular(self, timezone=None):
        return {
            'id': self.id,
            'origin': self.origin,
            'customer': self.customer,
            'tags': ','.join(self.tags),
            'attributes': self.attributes,
            'createTime': DateTime.localtime(self.create_time, timezone),

            'receiveTime': DateTime.localtime(self.receive_time, timezone),