Skip to content

Commit 1ed80be

Browse files
committed
Be stricter on month=0
This relates #6
1 parent 3f6673b commit 1ed80be

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

docs/CHANGES.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Changelog
22
==============
33

4-
1.0.16 (unreleased)
4+
1.1.0 (unreleased)
55
-------------------
66

7-
- Nothing changed yet.
8-
7+
- Enforce validation for month=1. Before this release we used to support month=0 and it was silently glided to month=1 to support having both day in month in 4th field when it came to have 6fields cron forms (second repeat). It will now raises a CroniterBadDateError. See https://github.com/kiorky/croniter/issues/6
8+
[kiorky]
99

1010
1.0.15 (2021-06-25)
1111
-------------------

src/croniter/croniter.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,13 @@ def _expand(cls, expr_format, hash_id=None):
712712
except ValueError:
713713
pass
714714

715-
if t in cls.LOWMAP[i]:
715+
if t in cls.LOWMAP[i] and not (
716+
# do not support 0 as a month either for classical 5 fields cron
717+
# or 6fields second repeat form
718+
# but still let conversion happen if day field is shifted
719+
(i == 3 and len(expressions) == 5) or
720+
(i == 4 and len(expressions) == 6)
721+
):
716722
t = cls.LOWMAP[i][t]
717723

718724
if (

src/croniter/tests/test_croniter.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ def testOptimizeCronExpressions(self):
317317
wildcard = ['*']
318318
m, h, d, mon, dow, s = range(6)
319319
# Test each field individually
320-
self.assertEqual(croniter('0-59 0 0 0 0').expanded[m], wildcard)
321-
self.assertEqual(croniter('0 0-23 0 0 0').expanded[h], wildcard)
322-
self.assertEqual(croniter('0 0 0-31 0 0').expanded[d], wildcard)
320+
self.assertEqual(croniter('0-59 0 0 1 0').expanded[m], wildcard)
321+
self.assertEqual(croniter('0 0-23 0 1 0').expanded[h], wildcard)
322+
self.assertEqual(croniter('0 0 0-31 1 0').expanded[d], wildcard)
323323
self.assertEqual(croniter('0 0 0 1-12 0').expanded[mon], wildcard)
324-
self.assertEqual(croniter('0 0 0 0 0-6').expanded[dow], wildcard)
325-
self.assertEqual(croniter('0 0 0 0 1-7').expanded[dow], wildcard)
326-
self.assertEqual(croniter('0 0 0 0 1-7,sat#3').expanded[dow], wildcard)
327-
self.assertEqual(croniter('0 0 0 0 0 0-59').expanded[s], wildcard)
324+
self.assertEqual(croniter('0 0 0 1 0-6').expanded[dow], wildcard)
325+
self.assertEqual(croniter('0 0 0 1 1-7').expanded[dow], wildcard)
326+
self.assertEqual(croniter('0 0 0 1 1-7,sat#3').expanded[dow], wildcard)
327+
self.assertEqual(croniter('0 0 0 1 0 0-59').expanded[s], wildcard)
328328
# Real life examples
329329
self.assertEqual(croniter('30 1-12,0,10-23 15-21 * fri').expanded[h], wildcard)
330330
self.assertEqual(croniter('30 1-23,0 15-21 * fri').expanded[h], wildcard)
@@ -993,12 +993,12 @@ def test_issue_monsun_117(self):
993993
'2019-01-17 00:00:01',
994994
'2019-01-18 00:00:02',
995995
'2019-01-19 00:00:03',
996-
'2019-01-20 00:00:04',
997996
'2019-01-23 00:00:00',
998997
'2019-01-24 00:00:01',
999998
'2019-01-25 00:00:02',
1000999
'2019-01-26 00:00:03',
1001-
'2019-01-27 00:00:04'])
1000+
'2019-01-30 00:00:00',
1001+
'2019-01-31 00:00:01'])
10021002

10031003
def test_mixdow(self):
10041004
base = datetime(2018, 10, 1, 0, 0)
@@ -1433,11 +1433,14 @@ def test_issue156(self):
14331433

14341434
def test_confirm_sort(self):
14351435
m, h, d, mon, dow, s = range(6)
1436-
self.assertListEqual(croniter('0 8,22,10,23 0 0 0').expanded[h], [8, 10, 22, 23])
1437-
self.assertListEqual(croniter('0 0 25-L 0 0').expanded[d], [25, 26, 27, 28, 29, 30, 31])
1436+
self.assertListEqual(croniter('0 8,22,10,23 0 1 0').expanded[h], [8, 10, 22, 23])
1437+
self.assertListEqual(croniter('0 0 25-L 1 0').expanded[d], [25, 26, 27, 28, 29, 30, 31])
14381438
self.assertListEqual(croniter("1 1 7,14,21,L * *").expanded[d], [7, 14, 21, "l"])
14391439
self.assertListEqual(croniter("0 0 * * *,sat#3").expanded[dow], ["*", 6])
14401440

1441+
def test_issue_k6(self):
1442+
self.assertRaises(CroniterBadCronError, croniter, '0 0 0 0 0')
1443+
14411444

14421445
if __name__ == '__main__':
14431446
unittest.main()

0 commit comments

Comments
 (0)