

def before(base=_datetime, diff=None):
    '\n    count datetime before `base` time\n    :param base:  minuend -> str/datetime/date\n    :param diff:  str\n    :return: datetime\n    '
    _base = parse(base)
    if isinstance(_base, datetime.date):
        _base = midnight(_base)
    if (not diff):
        return _base
    result_dict = dp(diff)
    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