croniter provides iteration for datetime object with cron like format

译文:croniter为datetime对象提供类似cron格式的迭代

相关文档

安装

pip install croniter

示例

# -*- coding: utf-8 -*-

from croniter import croniter
from datetime import datetime

# every 5 minutes
cron = '*/5 * * * *'

# 验证cron表达式
is_valid = croniter.is_valid(cron)
print(is_valid)
# True

# 执行计划
base = datetime(2010, 1, 25, 4, 46)

iter = croniter(cron, base)

print(iter.get_next(datetime))  # 2010-01-25 04:50:00
print(iter.get_next(datetime))  # 2010-01-25 04:55:00
print(iter.get_next(datetime))  # 2010-01-25 05:00:00