cast timestamp to datetime or date str

def cast_datetime(ts, fmt=None):
    """cast timestamp to datetime or date str"""
    dt = datetime.datetime.fromtimestamp(ts)
    if fmt:
        return dt.strftime(fmt)
    return dt