(value, tz=None)
return isoformat
Converts an OpenMRS timestamp to ISO format. Accepts a timezone,
    which defaults to UTC. If timezone is given, ISO format includes the
    offset, otherwise it ends in "Z".

    An OpenMRS timestamp is a Unix timestamp * 1000 (i.e. with
    milliseconds). Given None returns None. Raises ValueError for
    non-numeric values.

    >>> omrs_timestamp_to_datetime(1551564000000)
    '2019-03-02T22:00:00Z'
    >>> tz = datetime.timezone(datetime.timedelta(hours=+2), 'CAT')
    >>> omrs_timestamp_to_datetime(1551564000000, tz)
    '2019-03-03T00:00:00+02:00'
    >>> omrs_timestamp_to_datetime(1551564000)
    '2019-03-02T22:00:00Z'
Converts an OpenMRS timestamp to ISO format. Accepts a timezone,
    which defaults to UTC. If timezone is given, ISO format includes the
    offset, otherwise it ends in "Z".
Converts an OpenMRS timestamp to ISO format . Accepts a timezone which defaults to UTC . If timezone is given ISO format includes the offset otherwise it ends in Z .
def omrs_timestamp_to_datetime(value, tz=None):
    """
    Converts an OpenMRS timestamp to ISO format. Accepts a timezone,
    which defaults to UTC. If timezone is given, ISO format includes the
    offset, otherwise it ends in "Z".

    An OpenMRS timestamp is a Unix timestamp * 1000 (i.e. with
    milliseconds). Given None returns None. Raises ValueError for
    non-numeric values.

    >>> omrs_timestamp_to_datetime(1551564000000)
    '2019-03-02T22:00:00Z'
    >>> tz = datetime.timezone(datetime.timedelta(hours=+2), 'CAT')
    >>> omrs_timestamp_to_datetime(1551564000000, tz)
    '2019-03-03T00:00:00+02:00'
    >>> omrs_timestamp_to_datetime(1551564000)
    '2019-03-02T22:00:00Z'

    """
    if value is None:
        return None
    try:
        timestamp = int(value)
    except ValueError:
        raise ValueError(f"{value!r} is not an OpenMRS timestamp")
    max_seconds = datetime.datetime(datetime.MAXYEAR, 12, 31).timestamp()
    seconds_since_1970 = timestamp / 1000 if timestamp > max_seconds else timestamp
    dt = datetime.datetime.fromtimestamp(seconds_since_1970, tz)
    isoformat = dt.isoformat()
    if not dt.utcoffset():
        isoformat += "Z"
    return isoformat
def omrs_timestamp_to_datetime ( value , tz = None ) : if value is None : return None try : timestamp = int ( value ) except ValueError : raise ValueError ( f"{value!r} is not an OpenMRS timestamp" ) max_seconds = datetime . datetime ( datetime . MAXYEAR , 12 , 31 ) . timestamp ( ) seconds_since_1970 = timestamp / 1000 if timestamp > max_seconds else timestamp dt = datetime . datetime . fromtimestamp ( seconds_since_1970 , tz ) isoformat = dt . isoformat ( ) if not dt . utcoffset ( ) : isoformat += "Z" return isoformat