Skip to content

Commit fabb5cc

Browse files
authored
Merge pull request #7 from gilles-crealp/bug-begin-value
Correction of the beginning value
2 parents c0c8a25 + 76b61ec commit fabb5cc

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

crontools/crontab.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import dataclasses as dc
33
import datetime as dt
44
import heapq
5+
from math import ceil
56
import operator as op
67
import tzlocal
78
from typing import Any, ClassVar, Dict, Generic, Iterator, Iterable, Optional, Type, TypeVar, Tuple
@@ -141,7 +142,8 @@ def iter(self, start_from: Optional[int] = None) -> Iterator[int]:
141142
step = 1 if self.step is None else self.step
142143

143144
if start_from is not None:
144-
begin = max(begin, start_from)
145+
steps = ceil(max(start_from - begin, 0) / step)
146+
begin = begin + steps * step
145147

146148
return iter(range(begin, end + 1, step))
147149

tests/test_crontab.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,54 @@ def test_cron_str(expr, seconds_ext, year_ext):
226226
@pytest.mark.parametrize(
227227
'expr, Field, result, start_from',
228228
[
229+
(
230+
'*/10',
231+
SecondsField,
232+
[0, 10, 20, 30, 40, 50],
233+
None,
234+
),
235+
(
236+
'*/10',
237+
SecondsField,
238+
[20, 30, 40, 50],
239+
15,
240+
),
229241
(
230242
'*/10',
231243
MinuteField,
232244
[0, 10, 20, 30, 40, 50],
233245
None,
234246
),
247+
(
248+
'*/10',
249+
MinuteField,
250+
[20, 30, 40, 50],
251+
15,
252+
),
235253
(
236254
'1,2,5,10-20/2,13,40,40',
237255
MinuteField,
238256
[1, 2, 5, 10, 12, 13, 14, 16, 18, 20, 40],
239257
None,
240258
),
259+
(
260+
'1,2,5,10-20/2,13,40,40',
261+
MinuteField,
262+
[5, 10, 12, 13, 14, 16, 18, 20, 40],
263+
3,
264+
),
241265
(
242266
'8-23',
243267
HourField,
244268
[20, 21, 22, 23],
245269
20,
246270
),
271+
(
272+
'*/12',
273+
HourField,
274+
[12],
275+
5,
276+
),
247277
(
248278
'*',
249279
MonthdayField,

0 commit comments

Comments
 (0)