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

ValueError: day is out of range for month - on next iteration #58

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kavilakshmi
Copy link

Expression: "0 0 9/10 * ? *"

@pitchblack408
Copy link
Owner

pitchblack408 commented Nov 27, 2023

Hi, thank you for contributing. I looked at the expression and I haven't used one like this one before. In addition, I didn't get that exception. Can you add a test case the for the specific use case?

Input cron(0 0 9/10 * ? *), occurrence: 2020-05-09 22:30:57+00:00
Result: 2020-05-19 00:00:00+00:00
Input cron(0 0 9/10 * ? *), occurrence: 2020-05-19 00:00:00+00:00
Result: 2020-05-29 00:00:00+00:00
Input cron(0 0 9/10 * ? *), occurrence: 2020-05-29 00:00:00+00:00
Result: 2020-06-09 00:00:00+00:00

@kavilakshmi
Copy link
Author

kavilakshmi commented Apr 2, 2024

Hi @pitchblack408,

Am added snippet i've to to replicate the issue here.
---REASON---

Next occurrence looking for 29th day in non-leap years (february) .

--SUPPORT SNIPPET--

`
from datetime import datetime, timezone
from pyawscron import AWSCron

start_dt = datetime(year=2023, month=1, day=1, tzinfo=timezone.utc)
count = 10
aws_cron = AWSCron(cron='0 0 9/10 * ? *')
while count:
start_dt = aws_cron.occurrence(start_dt).next()
print(start_dt)
count -= 1

`
---and the exception----

Traceback (most recent call last):
File "/home/ubuntu/Desktop/training/pyawscron_fix.py", line 10, in
start_dt = aws_cron.occurrence(start_dt).next()
File "/home/ubuntu/Desktop/training/.venv/lib/python3.10/site-packages/pyawscron/occurrence.py", line 138, in next
return self.__find_once(self.cron, dt)
File "/home/ubuntu/Desktop/training/.venv/lib/python3.10/site-packages/pyawscron/occurrence.py", line 68, in __find_once
return self.__find_once(parsed, dt)
File "/home/ubuntu/Desktop/training/.venv/lib/python3.10/site-packages/pyawscron/occurrence.py", line 63, in __find_once
return self.__find_once(parsed, dt)
File "/home/ubuntu/Desktop/training/.venv/lib/python3.10/site-packages/pyawscron/occurrence.py", line 70, in __find_once
return datetime.datetime(year, month, day_of_month, hour, minute, tzinfo=datetime.timezone.utc)
ValueError: day is out of range for month

---AFTER THE FIX---
2022-01-09 00:00:00+00:00
2022-01-19 00:00:00+00:00
2022-01-29 00:00:00+00:00
2022-02-09 00:00:00+00:00
2022-02-19 00:00:00+00:00
2022-03-09 00:00:00+00:00
2022-03-19 00:00:00+00:00
2022-03-29 00:00:00+00:00
2022-04-09 00:00:00+00:00
2022-04-19 00:00:00+00:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants