from datetime import datetime


def format_timestamp_fn(dst_key):
    """Create a function to format a unix epoch string to iso8601 format.

    Arguments:
        dst_key (str): The destination key name

    Returns:
        function: The function that will format a datetime
    """
    def format(val, **kwargs):
        # Could be a tuple, e.g.: (352523325, 323, 43)
        if val and val[0] == '(':
            parts = val.strip('()').split(',')
            val = parts[0].strip()

        # Convert first part from seconds UTC
        try:
            val = datetime.utcfromtimestamp(int(val))
            return dst_key, val.isoformat() + 'Z'
        except ValueError:
            return None
    return format