FAILURE MAP
← Case archive

FA-77281 / Calendar recurrence rules / Open access

Closed-form final date of a COUNT-limited weekly BYDAY series: full weeks · case 01

When the remaining count is a multiple of the weekday count, the end date is one week early.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The number of full weeks after the first is computed with a plain floor division.

THE FAILURE

The number of full weeks after the first is computed with a plain floor division.

Unsuccessful approach: The partial repair `(rest + 1) // len(days)` rounds the other way and overshoots for most remainders.

Case contract

For FREQ=WEEKLY;INTERVAL;BYDAY;WKST;COUNT starting at dtstart (weeks begin on wkst, days of the first week before dtstart are skipped, active weeks every interval weeks from the dtstart week), compute the date of the final instance arithmetically, without expanding. count < 1 returns None. The result must equal the last element of the full expansion.

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(dtstart, interval, byday, wkst, count):
    start = dt.date.fromisoformat(dtstart)
    if count < 1:
        return None
    days = sorted(set(byday), key=lambda w: (w - wkst) % 7)
    week0 = start - dt.timedelta(days=(start.weekday() - wkst) % 7)
    first_week = [w for w in days if (w - wkst) % 7 >= (start.weekday() - wkst) % 7]
    if count <= len(first_week):
        w = first_week[count - 1]
        weeks = 0
    else:
        rest = count - len(first_week)
        weeks = rest // len(days)
        w = days[(rest - 1) % len(days)]
    last = week0 + dt.timedelta(days=weeks * interval * 7 + (w - wkst) % 7)
    return last.isoformat()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('WKST=MO interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 0, 4], '1997-08-24'),
  ('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None)],
 [('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23')],
 [('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12')],
 [('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12'),
  ('long series', ['2025-02-03', 2, [1, 3, 5], 0, 11], '2025-03-20'),
  ('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21')],
 [('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12'),
  ('long series', ['2025-02-03', 2, [1, 3, 5], 0, 11], '2025-03-20'),
  ('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('WKST=MO interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 0, 4], '1997-08-24'),
  ('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15')]]
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 fixtureActualExpectedOutcome
regression: WKST=SU interval 2 TU,SU1997-08-171997-08-31Failed
WKST=MO interval 2 TU,SU1997-08-241997-08-24Passed
multiple of weekday count2024-01-122024-01-12Passed
partial first week2024-01-082024-01-15Failed
interval 3 single day2024-06-212024-06-21Passed
count zeroNoneNonePassed
count negativeNoneNonePassed

SHA-256 / d800b0bcd3d6b26a5d7376e3ce1713ebc0c037710b9034a6852130afedde8db4

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(dtstart, interval, byday, wkst, count):
    start = dt.date.fromisoformat(dtstart)
    if count < 1:
        return None
    days = sorted(set(byday), key=lambda w: (w - wkst) % 7)
    week0 = start - dt.timedelta(days=(start.weekday() - wkst) % 7)
    first_week = [w for w in days if (w - wkst) % 7 >= (start.weekday() - wkst) % 7]
    if count <= len(first_week):
        w = first_week[count - 1]
        weeks = 0
    else:
        rest = count - len(first_week)
        weeks = (rest + 1) // len(days)
        w = days[(rest - 1) % len(days)]
    last = week0 + dt.timedelta(days=weeks * interval * 7 + (w - wkst) % 7)
    return last.isoformat()
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('WKST=MO interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 0, 4], '1997-08-24'),
  ('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None)],
 [('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23')],
 [('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12')],
 [('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None),
  ('within first week', ['2024-01-01', 2, [0, 1, 2], 0, 2], '2024-01-02'),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12'),
  ('long series', ['2025-02-03', 2, [1, 3, 5], 0, 11], '2025-03-20'),
  ('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('interval 3 single day', ['2024-05-06', 3, [4], 0, 3], '2024-06-21')],
 [('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23'),
  ('WKST=WE interval 2', ['2024-06-04', 2, [0, 3], 2, 7], '2024-07-25'),
  ('dtstart after all first-week days', ['2024-01-06', 2, [0, 1], 0, 5], '2024-02-12'),
  ('long series', ['2025-02-03', 2, [1, 3, 5], 0, 11], '2025-03-20'),
  ('regression: WKST=SU interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 6, 4], '1997-08-31'),
  ('WKST=MO interval 2 TU,SU', ['1997-08-05', 2, [1, 6], 0, 4], '1997-08-24'),
  ('multiple of weekday count', ['2024-01-01', 1, [0, 2, 4], 0, 6], '2024-01-12'),
  ('partial first week', ['2024-01-04', 1, [0, 2, 4], 0, 5], '2024-01-15')]]
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 fixtureActualExpectedOutcome
regression: WKST=SU interval 2 TU,SU1997-08-311997-08-31Passed
WKST=MO interval 2 TU,SU1997-08-241997-08-24Passed
multiple of weekday count2024-01-122024-01-12Passed
partial first week2024-01-082024-01-15Failed
interval 3 single day2024-07-122024-06-21Failed
count zeroNoneNonePassed
count negativeNoneNonePassed

SHA-256 / 9b20e30b0ef1aabbb4179f2d72e5243a777e433f22af0ff04525e0cc034bad8d

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:23.952407+00:00.

Case digest / 018aa2f3cb7bb3666b4faa3410c50f39850d166f1c5be3091be1e5923cb2c122