kiorky / croniter

MIT License
400 stars 39 forks source link

`*/90 * * * *` resolves to an hourly schedule #50

Closed prha closed 1 year ago

prha commented 1 year ago
>>> it = croniter('*/90 * * * *')
>>> it.get_next(datetime).isoformat()
'2023-07-14T17:00:00'
>>> it.get_next(datetime).isoformat()
'2023-07-14T18:00:00'
>>> it.get_next(datetime).isoformat()
'2023-07-14T19:00:00'
kiorky commented 1 year ago

It's not a bug, but what was intended:

image

for your use case, this can be a solution:

>>> base = datetime(2010, 8, 24, 23, 59)
>>> it1 = croniter('0 */3 * * *', base)
>>> it2 = croniter('30 1-23/3 * * *', base)
>>> times  = [it1.get_next(datetime) for i in range(8)]
>>> times += [it2.get_next(datetime) for i in range(8)]
>>> times.sort()
>>> pprint(times)
[datetime.datetime(2010, 8, 25, 0, 0),
 datetime.datetime(2010, 8, 25, 1, 30),
 datetime.datetime(2010, 8, 25, 3, 0),
 datetime.datetime(2010, 8, 25, 4, 30),
 datetime.datetime(2010, 8, 25, 6, 0),
 datetime.datetime(2010, 8, 25, 7, 30),
 datetime.datetime(2010, 8, 25, 9, 0),
 datetime.datetime(2010, 8, 25, 10, 30),
 datetime.datetime(2010, 8, 25, 12, 0),
 datetime.datetime(2010, 8, 25, 13, 30),
 datetime.datetime(2010, 8, 25, 15, 0),
 datetime.datetime(2010, 8, 25, 16, 30),
 datetime.datetime(2010, 8, 25, 18, 0),
 datetime.datetime(2010, 8, 25, 19, 30),
 datetime.datetime(2010, 8, 25, 21, 0),
 datetime.datetime(2010, 8, 25, 22, 30)]