watchdogs/utils.py
def check_work_time(work_hours, now: Optional[datetime] = None):
    """Check time if fit work_hours.

    :: Test Code

        from watchdogs.utils import check_work_time, datetime

        now = datetime.strptime('2020-03-14 11:47:32', '%Y-%m-%d %H:%M:%S')

        oks = [
            '0, 24',
            '[1, 2, 3, 11]',
            '[1, 2, 3, 11];%Y==2020',
            '%d==14',
            '16, 24|[11]',
            '16, 24|%M==47',
            '%M==46|%M==47',
            '%H!=11|%d!=12',
            '16, 24|%M!=41',
        ]

        for work_hours in oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert ok

        no_oks = [
            '0, 5',
            '[1, 2, 3, 5]',
            '[1, 2, 3, 11];%Y==2021',
            '%d==11',
            '16, 24|[12]',
            '%M==17|16, 24',
            '%M==46|[1, 2, 3]',
            '%H!=11&%d!=12',
            '%M!=46;%M!=47',
        ]

        for work_hours in no_oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert not ok


    """
    now = now or datetime.now()
    if '|' in work_hours:
        if '&' in work_hours or ';' in work_hours:
            raise ValueError('| can not use with "&" or ";"')
        return any((_check_work_time(partial_work_hour, now)
                    for partial_work_hour in work_hours.split('|')))
    else:
        if ('&' in work_hours or ';' in work_hours) and '|' in work_hours:
            raise ValueError('| can not use with "&" or ";"')
        return all((_check_work_time(partial_work_hour, now)
                    for partial_work_hour in re.split('&|;', work_hours)))
Check time if fit work_hours.

    :: Test Code

        from watchdogs.utils import check_work_time, datetime

        now = datetime.strptime('2020-03-14 11:47:32', '%Y-%m-%d %H:%M:%S')

        oks = [
            '0, 24',
            '[1, 2, 3, 11]',
            '[1, 2, 3, 11];%Y==2020',
            '%d==14',
            '16, 24|[11]',
            '16, 24|%M==47',
            '%M==46|%M==47',
            '%H!=11|%d!=12',
            '16, 24|%M!=41',
        ]

        for work_hours in oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert ok

        no_oks = [
            '0, 5',
            '[1, 2, 3, 5]',
            '[1, 2, 3, 11];%Y==2021',
            '%d==11',
            '16, 24|[12]',
            '%M==17|16, 24',
            '%M==46|[1, 2, 3]',
            '%H!=11&%d!=12',
            '%M!=46;%M!=47',
        ]

        for work_hours in no_oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert not ok


    
Check time if fit work_hours.
Check time if fit work_hours .
def check_work_time(work_hours, now: Optional[datetime] = None):
    now = now or datetime.now()
    if '|' in work_hours:
        if '&' in work_hours or ';' in work_hours:
            raise ValueError('| can not use with "&" or ";"')
        return any((_check_work_time(partial_work_hour, now)
                    for partial_work_hour in work_hours.split('|')))
    else:
        if ('&' in work_hours or ';' in work_hours) and '|' in work_hours:
            raise ValueError('| can not use with "&" or ";"')
        return all((_check_work_time(partial_work_hour, now)
                    for partial_work_hour in re.split('&|;', work_hours)))
def check_work_time ( work_hours , now : Optional [ datetime ] = None ) : now = now or datetime . now ( ) if '|' in work_hours : if '&' in work_hours or ';' in work_hours : raise ValueError ( '| can not use with "&" or ";"' ) return any ( ( _check_work_time ( partial_work_hour , now ) for partial_work_hour in work_hours . split ( '|' ) ) ) else : if ( '&' in work_hours or ';' in work_hours ) and '|' in work_hours : raise ValueError ( '| can not use with "&" or ";"' ) return all ( ( _check_work_time ( partial_work_hour , now ) for partial_work_hour in re . split ( '&|;' , work_hours ) ) )
Check time if fit work_hours.
Check time if fit work_hours .
"""Check time if fit work_hours.

    :: Test Code

        from watchdogs.utils import check_work_time, datetime

        now = datetime.strptime('2020-03-14 11:47:32', '%Y-%m-%d %H:%M:%S')

        oks = [
            '0, 24',
            '[1, 2, 3, 11]',
            '[1, 2, 3, 11];%Y==2020',
            '%d==14',
            '16, 24|[11]',
            '16, 24|%M==47',
            '%M==46|%M==47',
            '%H!=11|%d!=12',
            '16, 24|%M!=41',
        ]

        for work_hours in oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert ok

        no_oks = [
            '0, 5',
            '[1, 2, 3, 5]',
            '[1, 2, 3, 11];%Y==2021',
            '%d==11',
            '16, 24|[12]',
            '%M==17|16, 24',
            '%M==46|[1, 2, 3]',
            '%H!=11&%d!=12',
            '%M!=46;%M!=47',
        ]

        for work_hours in no_oks:
            ok = check_work_time(work_hours, now)
            print(ok, work_hours)
            assert not ok


    """
work_hours
now
Optional[datetime]
Test
None