DDayThistle
Workflows

Coding workflows · Holiday-aware working-day shifts

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Holiday-aware working-day shifts

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗