Reputation: 36
I want to know what's the last time instance is given a cron job?
Ex:
Cron expression @hourly
If I run the code at Oct 23 2:30 pm (datetime.now()), it should return Oct 22 2:00 pm.
I know Java has a package but any implementation in Python?
Thanks.
Upvotes: 0
Views: 2259
Reputation: 131
from croniter import croniter
from datetime import datetime
base = datetime(2020,11,21,00,13)
print(base)
expression = "30 * * * *"
itr = croniter(expression,base)
print(itr.get_next(datetime))
print(itr.get_prev(datetime))
print(itr.get_prev(datetime))
Upvotes: 3
Reputation: 36
Found the package at last!
Croniter
https://pypi.org/project/croniter/
Upvotes: 1