Skip to content

Commit 217346e

Browse files
authored
Merge pull request #8 from dapper91/dev
Dev
2 parents 0d87c96 + fa791ce commit 217346e

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
0.1.5 (2022-04-24)
5+
------------------
6+
7+
- range iter method beginning value initialization bug fixed.
8+
9+
410
0.1.4 (2021-03-19)
511
------------------
612

crontools/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__ = 'Python cron tools'
33
__url__ = 'https://github.com/dapper91/crontools'
44

5-
__version__ = '0.1.4'
5+
__version__ = '0.1.5'
66

77
__author__ = 'Dmitry Pershin'
88
__email__ = '[email protected]'

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)