When running a config with an nth day config:
n
schedule: nth: n: 3 weekday: Sat
I received
Error creating ticket: day is out of range for month
assigned to @btasker
The issue occurs within first_dow() (that's what I get for lifting code from Stackoverflow...)
first_dow()
def first_dow(year, month, dow): ''' Derived from a Stackoverflow answer: https://stackoverflow.com/a/71688384 Credit@ Molomy ''' day = ((8 + dow) - date(year, month, 1).weekday()) % 7 return date(year, month, day)
We're currently in September and asking for the first Saturday. This month started on Sunday.
So, if we break the day calculation logic out a bit:
dow = 5 # saturday a = (8 + dow) # 13 b = date(2024, 9, 1).weekday() # 6 c = (a - b) # 7 day = 7 % 7 # 0
The next call tries to create a day with the date 2024-09-0 which is (obviously) invalid.
We need to adjust the logic so that it calculates correctly.
The correct value in this case would be 7 - the first saturday of Sep 2024 was the 7th.
But, we need to figure out how to get there.
I'm not sure that it's actually possible with that function - with modulo 7 we're never, ever, going to get the value 7 back.
Unfortunately, I think the entire function probably needs to be ripped and replaced
mentioned in commit c26600746be14dd2e3f8d7e7e7cddbb900d684a5
Commit: c26600746be14dd2e3f8d7e7e7cddbb900d684a5 Author: B Tasker Date: 2024-09-08T23:42:17.000+01:00
fix: rewrite function to calculate first occurrence of a weekday (utilities/gitlab_recurring_issue#10)
OK, replacement is done.
The new function is also able to accept a weekday name rather than an number (though it still accepts those too)
Activity
08-Sep-24 16:39
assigned to @btasker
08-Sep-24 16:44
The issue occurs within
first_dow()
(that's what I get for lifting code from Stackoverflow...)We're currently in September and asking for the first Saturday. This month started on Sunday.
So, if we break the day calculation logic out a bit:
The next call tries to create a day with the date 2024-09-0 which is (obviously) invalid.
We need to adjust the logic so that it calculates correctly.
08-Sep-24 16:49
The correct value in this case would be 7 - the first saturday of Sep 2024 was the 7th.
But, we need to figure out how to get there.
I'm not sure that it's actually possible with that function - with modulo 7 we're never, ever, going to get the value 7 back.
Unfortunately, I think the entire function probably needs to be ripped and replaced
08-Sep-24 22:42
mentioned in commit c26600746be14dd2e3f8d7e7e7cddbb900d684a5
Message
fix: rewrite function to calculate first occurrence of a weekday (utilities/gitlab_recurring_issue#10)
08-Sep-24 22:43
OK, replacement is done.
The new function is also able to accept a weekday name rather than an number (though it still accepts those too)