python
crontab
croniter
5 years, 2 months ago
# pip install croniter
import datetime
from croniter import croniter
def check_date_in_cron(date_str, cron_str):
base = datetime.datetime.strptime(date_str, "%Y-%m-%d")
it1 = croniter(cron_str, base)
base = base.date()
dt = it1.get_prev(datetime.datetime).date()
if base == dt:
return True
elif base > dt:
dt = it1.get_next(datetime.datetime).date()
if base == dt:
return True
return False
print(check_date_in_cron('2019-09-24', '0 0 * * *')) # True
print(check_date_in_cron('2019-09-24', '0 0 * * 1')) # False
print(check_date_in_cron('2019-09-23', '0 0 * * 1')) # True
2 Comments
Please Login to Comment Here