def METHOD_NAME(ts):
    if ts[-1] != 'Z':
        raise Exception("missing time zone marker Z")
    ts = ts[:-1]
    parts = ts.split(".")
    ts = datetime.strptime(parts[0], "%Y-%m-%dT%H:%M:%S")
    if len(parts[1]) > 6:
        parts[1] = parts[1][:6]  # ensure we always parse microseconds
    return ts + timedelta(microseconds=datetime.strptime(parts[1], "%f").microsecond)