FA-6556 / Calendar arithmetic / Open access
Nth weekday of month · case 01
Weekday offsets are measured from Monday rather than the month first day.
ROOT CAUSE
Weekday offsets are measured from Monday rather than the month first day.
VERIFIED REPAIR
Apply the specified mathematical contract directly, preserving all terms and boundary cases: return (date(year,month,1)+timedelta(days=(weekday-date(year,month,1).weekday())%7+7*(n-1))).isoformat() if (weekday-date(year,month,1).weekday())%7+7*(n-1)<calendar.monthrange(year,month)[1] else None
Unsuccessful approach: The occurrence count starts at one full week too late and spills into the next month.
Case contract
Valid ISO Gregorian dates in years 1 through 9999; generated dates must remain in that range. Month is 1 through 12 and zero-based weekday is Monday 0 through Sunday 6 unless the output convention says otherwise. n>=1; return None if the requested nth zero-based weekday does not occur in that month. Exact operational definition: (date(year,month,1)+timedelta(days=(weekday-date(year,month,1).weekday())%7+7*(n-1))).isoformat() if (weekday-date(year,month,1).weekday())%7+7*(n-1)<calendar.monthrange(year,month)[1] else None
Why this case matters
Small exact fixtures expose this error without platform timing, external services, or probabilistic observations. Calendar conventions results depend on the stated convention.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(year, month, weekday, n):
return (date(year,month,1)+timedelta(days=weekday+7*(n-1))).isoformat()
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (2024, 1, 0, 1)', solve(*(2024, 1, 0, 1)), '2024-01-01')
check('fixture 2: (2024, 2, 0, 1)', solve(*(2024, 2, 0, 1)), '2024-02-05')
check('fixture 3: (2024, 2, 3, 5)', solve(*(2024, 2, 3, 5)), '2024-02-29')
check('fixture 4: (2023, 2, 0, 5)', solve(*(2023, 2, 0, 5)), None)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| fixture 1: (2024, 1, 0, 1) | 2024-01-01 | 2024-01-01 | Passed |
| fixture 2: (2024, 2, 0, 1) | 2024-02-01 | 2024-02-05 | Failed |
| fixture 3: (2024, 2, 3, 5) | 2024-03-03 | 2024-02-29 | Failed |
| fixture 4: (2023, 2, 0, 5) | 2023-03-01 | None | Failed |
SHA-256 / 26b50932cad81876de8c1041f8d63c3f1ad62fe1f5f8e28943a2dfd708e30757
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(year, month, weekday, n):
return (date(year,month,1)+timedelta(days=(weekday-date(year,month,1).weekday())%7+7*n)).isoformat()
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (2024, 1, 0, 1)', solve(*(2024, 1, 0, 1)), '2024-01-01')
check('fixture 2: (2024, 2, 0, 1)', solve(*(2024, 2, 0, 1)), '2024-02-05')
check('fixture 3: (2024, 2, 3, 5)', solve(*(2024, 2, 3, 5)), '2024-02-29')
check('fixture 4: (2023, 2, 0, 5)', solve(*(2023, 2, 0, 5)), None)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| fixture 1: (2024, 1, 0, 1) | 2024-01-08 | 2024-01-01 | Failed |
| fixture 2: (2024, 2, 0, 1) | 2024-02-12 | 2024-02-05 | Failed |
| fixture 3: (2024, 2, 3, 5) | 2024-03-07 | 2024-02-29 | Failed |
| fixture 4: (2023, 2, 0, 5) | 2023-03-13 | None | Failed |
SHA-256 / c15483e16945bc45edf07dbf645fd52147d96ff6ae7f7547bcb4e5ee56e82bf9
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import calendar
import statistics
import itertools
from fractions import Fraction
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal, ROUND_HALF_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR
N = 1
observations = []
def solve(year, month, weekday, n):
return (date(year,month,1)+timedelta(days=(weekday-date(year,month,1).weekday())%7+7*(n-1))).isoformat() if (weekday-date(year,month,1).weekday())%7+7*(n-1)<calendar.monthrange(year,month)[1] else None
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fixture 1: (2024, 1, 0, 1)', solve(*(2024, 1, 0, 1)), '2024-01-01')
check('fixture 2: (2024, 2, 0, 1)', solve(*(2024, 2, 0, 1)), '2024-02-05')
check('fixture 3: (2024, 2, 3, 5)', solve(*(2024, 2, 3, 5)), '2024-02-29')
check('fixture 4: (2023, 2, 0, 5)', solve(*(2023, 2, 0, 5)), None)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| fixture 1: (2024, 1, 0, 1) | 2024-01-01 | 2024-01-01 | Passed |
| fixture 2: (2024, 2, 0, 1) | 2024-02-05 | 2024-02-05 | Passed |
| fixture 3: (2024, 2, 3, 5) | 2024-02-29 | 2024-02-29 | Passed |
| fixture 4: (2023, 2, 0, 5) | None | None | Passed |
SHA-256 / 5a4db94a2c21406169cb996ae64c57cd6146c43431e3dafa58cdc348fac5de79
Verification & scope
This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:38:03.121463+00:00.
Case digest / a23640b36c15c63acf722ebef3efa056851ee994de6ba8931e92f35bb3ab8473