def _closest_date(target_dt, date_list, before_target=None):
    '''
    This function finds the date in a list closest to the target date.
    An optional parameter can be given to get the closest before or after.

    :param target_dt: The target date
    :type target_dt: datetime.date
    :param date_list: The list of dates to search
    :type date_list: datetime.date list
    :param before_target: closest before or after the target
    :type before_target: bool or None
    :returns: The closest date
    :rtype: datetime.date or None
    '''
    fb = lambda d: d - target_dt if d >= target_dt else datetime.timedelta.max
    fa = lambda d: target_dt - d if d <= target_dt else datetime.timedelta.min
    fnone = lambda d: target_dt - d if d < target_dt else d - target_dt
    if before_target is None:
        return min(date_list, key=fnone).date()
    if before_target:
        return min(date_list, key=fb).date()
    else:
        return min(date_list, key=fa).date()
dataset/ETHPy150Open airbnb/airflow/airflow/macros/hive.py/_closest_date/swapped operands of `-`