taichino / croniter

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

get_prev() method doesn't take kare about seconds #32

Closed slavkoja closed 10 years ago

slavkoja commented 10 years ago

Hi, when i try, if it is proper solution fo mre, i find this:

base = datetime(2014, 6, 10, 12, 0, 10)

iter = croniter('0 */2 * * *', base)
print "current: %s" % iter.get_current(datetime).time()

iter = croniter('0 */2 * * *', base)
print "prev:    %s" % iter.get_prev(datetime).time()

iter = croniter('0 */2 * * *', base)
print "next:    %s" % iter.get_next(datetime).time()

Which prints:

current: 12:00:10
prev:    10:00:00
next:    14:00:00

When base time is 12:00:10, i expect that the get_prev() returns the "12:00:00", not the "10:00:00". When the base time is changed to "12:01:10" all is as expected:

current: 12:01:10
prev:    12:00:00
next:    14:00:00

To i get really previous time (and date) of the execution, i need to use:

iter.get_next(datetime)
print "prev:    %s" % iter.get_prev(datetime).time()

regards

kiorky commented 10 years ago

Nope, cron speaking, the result is correct, if you want to test the prev but in lazy mode, it's up to you to add the 1minute delta.