Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust list index out of range error cron(00 4 ? * 3-1 *) #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/pyawscron/awscron.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ def __parse_one_rule(self, rule, min, max):
parts = s.split('-')
start = int(parts[0])
end = int(parts[1])
for i in range(start, end + 1, 1):
allows.append(i)
if start <= end:
for i in range(start, end + 1):
allows.append(i)
else:
for i in range(start, 8):
allows.append(i)
for i in range(1, end + 1):
allows.append(i)
else:
allows.append(int(s))
allows.sort()
Expand Down
31 changes: 30 additions & 1 deletion tests/next_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,35 @@ def test_generate_multiple_next_14(self):
print(f"Result: {dt}\tExpected: {expected}\n")
self.assertEqual(expected, str(dt))

def test_generate_multiple_next_occurences15(self):
"""
Tests the generation of multiple next occurrences
from a specific CRON expression. Ensures that
days_of_week are within the expected range.
:return: None
"""
cron = '00 4 ? * 3-1 *'
expected_list= ['2024-11-14 04:00:00+00:00',
'2024-11-15 04:00:00+00:00',
'2024-11-16 04:00:00+00:00',
'2024-11-17 04:00:00+00:00',

'2024-11-19 04:00:00+00:00',
'2024-11-20 04:00:00+00:00',
'2024-11-21 04:00:00+00:00',
'2024-11-22 04:00:00+00:00',
'2024-11-23 04:00:00+00:00',
'2024-11-24 04:00:00+00:00']
cron = AWSCron(cron)
dt = datetime.datetime(2024, 11, 13, 12, 30, 57, tzinfo=datetime.timezone.utc)
results = []
for expected in expected_list:
print(f"Input {cron}, occurrence: {dt}")
dt = cron.occurrence(dt).next()
results.append(str(dt))
print(f"Result: {dt}\tExpected: {expected}\n")
self.assertEqual(expected, str(dt))


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