티스토리 뷰

공부

[croniter] match

승가비 2023. 4. 21. 01:36
728x90

https://stackoverflow.com/questions/4610904/calculate-next-scheduled-time-based-on-cron-spec

 

Calculate next scheduled time based on cron spec

What's an efficient way to calculate the next run time of an event given the current time and a cron spec? I'm looking for something other than "loop through every minute checking if it matches sp...

stackoverflow.com

https://github.com/kiorky/croniter

 

GitHub - kiorky/croniter

Contribute to kiorky/croniter development by creating an account on GitHub.

github.com

>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 0, 0, 0))
True
>>> croniter.match("0 0 * * *", datetime(2019, 1, 14, 0, 2, 0, 0))
False
>>>
>>> croniter.match("2 4 1 * wed", datetime(2019, 1, 1, 4, 2, 0, 0)) # 04:02 on every Wednesday OR on 1st day of month
True
>>> croniter.match("2 4 1 * wed", datetime(2019, 1, 1, 4, 2, 0, 0), day_or=False) # 04:02 on every 1st day of the month if it is a Wednesday
False
728x90
댓글