Open the context
Choose the project folder and name the files or behavior involved.
Shift a date by minus 366 through 366 working days, skipping weekends and up to 1000 holidays. Check zero, reverse shifts and calendar limits, rejecting invalid date types without changing the holiday set.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from datetime import date, timedelta
def working_day_shift(start, days, holidays):
if type(start) is not date or type(days) is not int or not -366 <= days <= 366:
raise ValueError("days.input")
if type(holidays) is not set or len(holidays) > 1000 or any(type(d) is not date for d in holidays):
raise ValueError("days.holidays")
remaining, step = abs(days), 1 if days >= 0 else -1
for _ in range(7*(remaining+len(holidays))+7):
if remaining == 0:
return start
try:
start += timedelta(days=step)
except OverflowError as error:
raise ValueError("days.range") from error
if start.weekday() < 5 and start not in holidays:
remaining -= 1
raise RuntimeError("days.steps")The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.