def find_closest_date( ts, date, search_min = True) :
    """
    Summary:
        Function that search for the closest date in a time series using
        a specific criteria (min/max)
        
    Arguments:
        ts - the time series where to search for the event
        date - the event date
        search_min - if true it searches for minumum value, if false for the
                    maximum
        
    Returns:
        close_date - the date in the time series satisfying the criteria
    """
    
    # find the previous and following date
    previous_date_ind = len((date - ts.index).days[(date - ts.index).days >= 0]) - 1
    
    if ts.index[previous_date_ind] == date :
        return date
    
    next_date_ind = previous_date_ind + 1
    
    if search_min :
        if ts[previous_date_ind] > ts[next_date_ind] :
            return ts.index[next_date_ind]
        else:
            return ts.index[previous_date_ind]
    else :
        if ts[previous_date_ind] < ts[next_date_ind] :
            return ts.index[next_date_ind]
        else:
            return ts.index[previous_date_ind]