Whole file

cuu508/cronsim

The author described this change as Fix weekday handling bugs. It counts as a record because the check below fails on the code as it stood at d8a1ce690 and passes on bf89dfff7, with nothing else changed between the two runs.

Fix saved2021-04-28
Sharing licenceBSD-3-Clause · LICENSE
Change size+6 9

What the code was meant to do, written into the code itself as a save note

Fix weekday handling bugs

The change

1616 list(range(0, 24)),
1717 list(range(1, 32)),
1818 list(range(1, 13)),
19- list(range(1, 8)),
19+ list(range(0, 7)),
2020 ]
2121
2222 SYMBOLIC_DAYS = "MON TUE WED THU FRI SAT SUN".split()
3232 if value.upper() in SYMBOLIC_DAYS:
3333 value = SYMBOLIC_DAYS.index(value.upper()) + 1
3434
35- # In cron, Monday=1. In Python, Monday=0.
36- return (int(value) - 1) % 7
37-
3835 return int(value)
3936
4037
145142 return True
146143
147144 # Does the day of the week match?
148- dow = d.weekday()
149- if dow in self.weekdays:
145+ dow = d.weekday() + 1
146+ if dow in self.weekdays or dow % 7 in self.weekdays:
150147 return True
151148
152- weekday_idx = (d.day + 6) // 7
153- if (dow, weekday_idx) in self.weekdays:
149+ idx = (d.day + 6) // 7
150+ if (dow, idx) in self.weekdays or (dow % 7, idx) in self.weekdays:
154151 return True
155152
156153 def advance_day(self):
209206
210207
211208 if __name__ == '__main__':
212- a = Wat("0 0 * * MON-FRI", datetime.now())
209+ a = Wat("0 1 * * */2", datetime.now())
213210 for i in range(0, 10):
214211 print("Here's what we got: ", next(a))
215212

The check that tells the two apart

failpass·test_wat.py::TestParse::test_it_handles_0_sunday

Check file test_wat.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itd8a1ce6900552a0a8aada836c099c908e52ae43d
Broken version dated2021-04-28
Modulewat
Units changedWat, _int
Fingerprint7d632ecc9a428011
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in cuu508/cronsim