taichino / croniter

croniter is a python module to provide iteration for datetime object.
http://github.com/taichino/croniter
387 stars 105 forks source link

When I set a multi-condition time, I got a wrong result. #126

Closed Hopetree closed 5 years ago

Hopetree commented 5 years ago

my test

# -*- coding:utf-8 -*-
from datetime import datetime
from croniter import croniter

class MyCroniter():
    def __init__(self,cronstr):
        self.cronstr = cronstr
        self.base_time = datetime.now()

    def get_time_list(self,n):
        itr = croniter(self.cronstr,self.base_time)
        lis = [itr.get_next(datetime).strftime('%F %T') for i in range(n)]
        print(lis)

if __name__ == '__main__':
    TEST = [
        '0 3,6,9 * * *',
        '0 5-12 * * *',
        '*/10 * * * *',
        '0 */2 10 * *',
        '0 0 31 * *',
        '0 11 4 * mon-wed',  # get bad time
        '*/5 5-10,14-20 * 1-5,9-12 1-5'
    ]
    for t in TEST:
        c = MyCroniter(t)
        c.get_time_list(3)

result

['2019-07-05 03:00:00', '2019-07-05 06:00:00', '2019-07-05 09:00:00']
['2019-07-05 05:00:00', '2019-07-05 06:00:00', '2019-07-05 07:00:00']
['2019-07-04 15:40:00', '2019-07-04 15:50:00', '2019-07-04 16:00:00']
['2019-07-10 00:00:00', '2019-07-10 02:00:00', '2019-07-10 04:00:00']
['2019-07-31 00:00:00', '2019-08-31 00:00:00', '2019-10-31 00:00:00']
['2019-07-08 11:00:00', '2019-07-09 11:00:00', '2019-07-10 11:00:00']
['2019-09-02 05:00:00', '2019-09-02 05:05:00', '2019-09-02 05:10:00']

you can see ,when i set the string '0 11 4 * mon-wed' i get a bad result like ['2019-07-08 11:00:00', '2019-07-09 11:00:00', '2019-07-10 11:00:00'] the real day should be 4

kiorky commented 5 years ago

Your test is not reproducible, do not use now().

Hopetree commented 5 years ago

@kiorky but when i change the base time self.base_time = datetime(2019,7,5,4,50) the result is also bad

kiorky commented 5 years ago

Feel free to reopen a reproducible test case, Thanks you !