FA-77121 / Calendar recurrence rules / Open access
Yearly ISO BYWEEKNO/BYDAY expansion: negative week · case 01
BYWEEKNO=-1 selects the second-to-last ISO week.
ROOT CAUSE
Negative week numbers are offset without the +1.
THE FAILURE
Negative week numbers are offset without the +1.
Unsuccessful approach: The partial repair `wn if wn > 0 else 52 + wn + 1` assumes every year has 52 weeks.
Case contract
FREQ=YEARLY with BYWEEKNO (ISO weeks, Monday start, week 1 contains January 4) and BYDAY weekdays (0=Monday). Negative week numbers count from the last ISO week of the year (-1 is the last). A year has 53 weeks exactly when December 28 falls in week 53; week numbers outside 1..weeks are ignored for that year. Dates may fall in the adjacent calendar year. Expand years year_start .. year_start+years-1 and return unique ISO dates sorted.
Why this case matters
Recurring calendar series are expanded into concrete instances for display, reminders and conflict checks.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year_start, weeknos, weekdays, years):
out = set()
for y in range(year_start, year_start + years):
jan4 = dt.date(y, 1, 4)
week1 = jan4 - dt.timedelta(days=jan4.weekday())
nweeks = dt.date(y, 12, 28).isocalendar()[1]
for wn in weeknos:
w = wn if wn > 0 else nweeks + wn
if not (1 <= w <= nweeks):
continue
for wd in weekdays:
out.add(week1 + dt.timedelta(days=(w - 1) * 7 + wd))
return sorted(d.isoformat() for d in out)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28']),
('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22']),
('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'])],
[('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22']),
('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27'])],
[('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01'])],
[('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01']),
('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28'])],
[('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01']),
('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28']),
('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22'])]]
for label, args, expected in fixtures[N-1]:
check(label, solve(*args), expected)
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 |
|---|---|---|---|
| regression: week 1 in 2021 | ['2021-01-04'] | ['2021-01-04'] | Passed |
| week 53 existence | ['2020-12-28'] | ['2020-12-28'] | Passed |
| last week negative | ['2020-12-27', '2021-12-26', '2022-12-25'] | ['2021-01-03', '2022-01-02', '2023-01-01'] | Failed |
| leap year starting wednesday | ['2024-12-16', '2025-12-15'] | ['2024-12-23', '2025-12-22'] | Failed |
| week 20 monday friday | ['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17'] | ['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17'] | Passed |
| too-negative week | ['2021-01-13'] | ['2021-01-13'] | Passed |
| week 1 sunday spans years | ['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'] | ['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'] | Passed |
SHA-256 / 16394a87f34f42b98de5d7426de97866f97fd6ce55c789fee49a493fd7191f86
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import datetime as dt
import calendar
N = 1
observations = []
def solve(year_start, weeknos, weekdays, years):
out = set()
for y in range(year_start, year_start + years):
jan4 = dt.date(y, 1, 4)
week1 = jan4 - dt.timedelta(days=jan4.weekday())
nweeks = dt.date(y, 12, 28).isocalendar()[1]
for wn in weeknos:
w = wn if wn > 0 else 52 + wn + 1
if not (1 <= w <= nweeks):
continue
for wd in weekdays:
out.add(week1 + dt.timedelta(days=(w - 1) * 7 + wd))
return sorted(d.isoformat() for d in out)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28']),
('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22']),
('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'])],
[('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22']),
('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27'])],
[('week 20 monday friday',
[2023, [20], [0, 4], 2],
['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17']),
('too-negative week', [2021, [-60, 2], [2], 1], ['2021-01-13']),
('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01'])],
[('week 1 sunday spans years',
[2015, [1, 52], [6], 2],
['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01']),
('second to last week', [2026, [-2], [3], 2], ['2026-12-24', '2027-12-23']),
('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01']),
('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28'])],
[('many weeks', [2027, [1, -1, 26], [0], 1], ['2027-01-04', '2027-06-28', '2027-12-27']),
('year starting saturday', [2022, [1, 53], [1, 5], 1], ['2022-01-04', '2022-01-08']),
('53 in 2026', [2026, [53], [4], 1], ['2027-01-01']),
('regression: week 1 in 2021', [2021, [1], [0], 1], ['2021-01-04']),
('week 53 existence', [2019, [53], [0], 3], ['2020-12-28']),
('last week negative', [2020, [-1], [6], 3], ['2021-01-03', '2022-01-02', '2023-01-01']),
('leap year starting wednesday', [2024, [-1, 53], [0], 2], ['2024-12-23', '2025-12-22'])]]
for label, args, expected in fixtures[N-1]:
check(label, solve(*args), expected)
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 |
|---|---|---|---|
| regression: week 1 in 2021 | ['2021-01-04'] | ['2021-01-04'] | Passed |
| week 53 existence | ['2020-12-28'] | ['2020-12-28'] | Passed |
| last week negative | ['2020-12-27', '2022-01-02', '2023-01-01'] | ['2021-01-03', '2022-01-02', '2023-01-01'] | Failed |
| leap year starting wednesday | ['2024-12-23', '2025-12-22'] | ['2024-12-23', '2025-12-22'] | Passed |
| week 20 monday friday | ['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17'] | ['2023-05-15', '2023-05-19', '2024-05-13', '2024-05-17'] | Passed |
| too-negative week | ['2021-01-13'] | ['2021-01-13'] | Passed |
| week 1 sunday spans years | ['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'] | ['2015-01-04', '2015-12-27', '2016-01-10', '2017-01-01'] | Passed |
SHA-256 / 3ad94faec08a546f4d9f420b72a80122c9487ac4718fc8f3166b1cd08f45e5eb
HELD IN THE MEMBER ARCHIVE
The verified repair and its recorded checks are member-only.
This mechanism has 7 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.
Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.
Member access is invitation-based. Sign in with your invited account to inspect the repair.
Sign in to the archive ↗Verification & scope
Stipulated, bounded recurrence-expansion model evaluated offline on explicit fixtures; it is not a complete iCalendar implementation and makes no claim of standards conformance. 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:49:22.593674+00:00.
Case digest / b29628fdacca7330708de4a1ca3acf42cb438e79c6aa1633083d437aa0c61656