def before(base=_datetime, diff=None):
    """
    count datetime before `base` time
    :param base:  minuend -> str/datetime/date
    :param diff:  str
    :return: datetime
    """
    _base = parse(base)
    if isinstance(_base, datetime.date):
        _base = midnight(_base)
    if not diff:
        return _base
    result_dict = dp(diff)
    # weeks already convert to days in diff_parse function(dp)
    for unit in result_dict:
        _val = result_dict[unit]
        if not _val:
            continue
        if unit == 'years':
            _base = _base.replace(year=(_base.year - _val))
        elif unit == 'months':
            if _base.month <= _val:
                _month_diff = 12 - (_val - _base.month)
                _base = _base.replace(year=_base.year - 1).replace(month=_month_diff)
            else:
                _base = _base.replace(month=_base.month - _val)
        elif unit in ['days', 'hours', 'minutes', 'seconds']:
            _base = _base - datetime.timedelta(**{unit: _val})
    return _base
dataset/ETHPy150Open shinux/PyTime/pytime/pytime.py/before/original