toucan_data_sdk/utils/postprocess/filter_by_date.py
def add_offset(dateobj, hr_offset: str, sign: str):
    """add a human readable offset to `dateobj` and return corresponding date.

    rely on `pandas.Timedelta` and add the following extra shortcuts:
    - "w", "week" and "weeks" for a week (i.e. 7days)
    - "month', "months" for a month (i.e. no day computation, just increment the month)
    - "y", "year', "years" for a year (i.e. no day computation, just increment the year)
    """
    sign_coeff = 1 if sign == '+' else -1
    try:
        return dateobj + sign_coeff * pd.Timedelta(hr_offset)
    except ValueError:
        # pd.Timedelta could not parse the offset, let's try harder
        match = TIMEDELTA_RGX.match(hr_offset)
        if match is not None:
            groups = match.groupdict()
            unit = groups['unit'].lower()[0]
            num = sign_coeff * int(groups['num'])
            # is it a week ?
            if unit == 'w':
                return dateobj + num * timedelta(weeks=1)
            # or a month ?
            if unit == 'm':
                return add_months(dateobj, num)
            # or a year ?
            if unit == 'y':
                return add_years(dateobj, num)
        # we did what we could, just re-raise the original exception
        raise
def add_offset(dateobj, hr_offset: str, sign: str):
    sign_coeff = 1 if sign == '+' else -1
    try:
        return dateobj + sign_coeff * pd.Timedelta(hr_offset)
    except ValueError:
        # pd.Timedelta could not parse the offset, let's try harder
        match = TIMEDELTA_RGX.match(hr_offset)
        if match is not None:
            groups = match.groupdict()
            unit = groups['unit'].lower()[0]
            num = sign_coeff * int(groups['num'])
            # is it a week ?
            if unit == 'w':
                return dateobj + num * timedelta(weeks=1)
            # or a month ?
            if unit == 'm':
                return add_months(dateobj, num)
            # or a year ?
            if unit == 'y':
                return add_years(dateobj, num)
        # we did what we could, just re-raise the original exception
        raise
def add_offset ( dateobj , hr_offset : str , sign : str ) : sign_coeff = 1 if sign == '+' else - 1 try : return dateobj + sign_coeff * pd . Timedelta ( hr_offset ) except ValueError : # pd.Timedelta could not parse the offset, let's try harder match = TIMEDELTA_RGX . match ( hr_offset ) if match is not None : groups = match . groupdict ( ) unit = groups [ 'unit' ] . lower ( ) [ 0 ] num = sign_coeff * int ( groups [ 'num' ] ) # is it a week ? if unit == 'w' : return dateobj + num * timedelta ( weeks = 1 ) # or a month ? if unit == 'm' : return add_months ( dateobj , num ) # or a year ? if unit == 'y' : return add_years ( dateobj , num ) # we did what we could, just re-raise the original exception raise
add a human readable offset to `dateobj` and return corresponding date.

    rely on `pandas.Timedelta` and add the following extra shortcuts:
    - "w", "week" and "weeks" for a week (i.e. 7days)
    - "month', "months" for a month (i.e. no day computation, just increment the month)
    - "y", "year', "years" for a year (i.e. no day computation, just increment the year)
add a human readable offset to dateobj and return corresponding date .