Month-End Inspections Overflow Into the Month After Next
Level 2 · node · Correctness · Day overflow into a later month when scheduling monthly inspections
Scenario
A fictional facility maintenance service stores each asset's last scheduled inspection date and its original preferred day of the month. An asset scheduled for the 31st should be inspected on the last day of February after January 31, then return to March 31. The current schedule API skips February and returns a date in early March. Trace the schedule repository, calculation service, and controller to examine how different month lengths are handled.
Requirements
Schedule the next inspection in the calendar month immediately after the last scheduled date. Use the preferred day if that day exists in the next month; otherwise clamp it to the last day of that month. Preserve the original preferred day so a longer subsequent month can use it again. Handle the December-to-January year transition. Return HTTP 404 for an unknown asset and keep the existing response structure.
Acceptance criteria
- When the preferred day exists in the next month, schedule the inspection on that same day.
- After January 31, the next inspection falls on the last day of February of that year.
- After August 31, the next inspection falls on September 30.
- After a December inspection, return the correct January date in the following year.
- After a short month, restore the stored preferred day when the next month is long enough.
- An unknown asset returns HTTP 404 with a null body.