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.
Projectcuu508/cronsim
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
| 16 | 16 | list(range(0, 24)), | |
| 17 | 17 | list(range(1, 32)), | |
| 18 | 18 | list(range(1, 13)), | |
| 19 | - | list(range(1, 8)), | |
| 19 | + | list(range(0, 7)), | |
| 20 | 20 | ] | |
| 21 | 21 | ||
| 22 | 22 | SYMBOLIC_DAYS = "MON TUE WED THU FRI SAT SUN".split() | |
| ⋯ | |||
| 32 | 32 | if value.upper() in SYMBOLIC_DAYS: | |
| 33 | 33 | value = SYMBOLIC_DAYS.index(value.upper()) + 1 | |
| 34 | 34 | ||
| 35 | - | # In cron, Monday=1. In Python, Monday=0. | |
| 36 | - | return (int(value) - 1) % 7 | |
| 37 | - | ||
| 38 | 35 | return int(value) | |
| 39 | 36 | ||
| 40 | 37 | ||
| ⋯ | |||
| 145 | 142 | return True | |
| 146 | 143 | ||
| 147 | 144 | # 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: | |
| 150 | 147 | return True | |
| 151 | 148 | ||
| 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: | |
| 154 | 151 | return True | |
| 155 | 152 | ||
| 156 | 153 | def advance_day(self): | |
| ⋯ | |||
| 209 | 206 | ||
| 210 | 207 | ||
| 211 | 208 | if __name__ == '__main__': | |
| 212 | - | a = Wat("0 0 * * MON-FRI", datetime.now()) | |
| 209 | + | a = Wat("0 1 * * */2", datetime.now()) | |
| 213 | 210 | for i in range(0, 10): | |
| 214 | 211 | print("Here's what we got: ", next(a)) | |
| 215 | 212 | ||
The check that tells the two apart
fail→pass·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
- 2023-04-27format_time
- 2021-04-28Fix more weekday handling bugs