FAILURE MAP
← Case archive

FA-77156 / Calendar recurrence rules / Open access

Monthly BYDAY restricted by BYMONTHDAY (Friday the 13th): weekday numbering · case 01

BYDAY=FR;BYMONTHDAY=13 returns Thursday the 13th.

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

ROOT CAUSE

Weekday codes are numbered from Sunday while date.weekday() numbers from Monday.

THE FAILURE

Weekday codes are numbered from Sunday while date.weekday() numbers from Monday.

Unsuccessful approach: The partial repair `['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].index(w) - 1` shifts by one without wrapping, so SU maps to -1 and never matches.

Case contract

FREQ=MONTHLY with BYDAY weekday codes (MO..SU) and BYMONTHDAY values (negative counts from month end). When both are present a day must satisfy both; an empty list imposes no restriction. Days are examined from dtstart forward. Return the first count ISO dates (search bounded to 50 years).

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, byday, bymonthday, count):
    start = dt.date.fromisoformat(dtstart)
    wanted = [['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].index(w) for w in byday]
    out = []
    d = start
    while len(out) < count and d.year < start.year + 50:
        dim = calendar.monthrange(d.year, d.month)[1]
        day_ok = not wanted or d.weekday() in wanted
        mday_ok = not bymonthday or (d.day in bymonthday or d.day - dim - 1 in bymonthday)
        if day_ok and mday_ok:
            out.append(d.isoformat())
        d += dt.timedelta(days=1)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01'])],
 [('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15'])],
 [('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13'])],
 [('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01'])],
 [('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31'])]]
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: friday the 13th['2024-01-13', '2024-04-13', '2024-07-13']['2024-09-13', '2024-12-13', '2025-06-13']Failed
last sunday via -1..-7['2024-01-29', '2024-02-26', '2024-03-25']['2024-01-28', '2024-02-25', '2024-03-31']Failed
only bymonthday['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']Passed
only byday['2024-01-01', '2024-01-07', '2024-01-08', '2024-01-14']['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']Failed
last day monday['2024-04-30', '2024-12-31']['2024-09-30', '2025-03-31']Failed
first monday via 1..7['2024-02-06', '2024-03-05', '2024-04-02']['2024-02-05', '2024-03-04', '2024-04-01']Failed
sunday first of month['2024-01-01', '2024-04-01']['2024-09-01', '2024-12-01']Failed

SHA-256 / 2527f2743d4ca80cd8886fc22c55eed1225a8a9c981749c2f1d92674099108d6

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, byday, bymonthday, count):
    start = dt.date.fromisoformat(dtstart)
    wanted = [['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].index(w) - 1 for w in byday]
    out = []
    d = start
    while len(out) < count and d.year < start.year + 50:
        dim = calendar.monthrange(d.year, d.month)[1]
        day_ok = not wanted or d.weekday() in wanted
        mday_ok = not bymonthday or (d.day in bymonthday or d.day - dim - 1 in bymonthday)
        if day_ok and mday_ok:
            out.append(d.isoformat())
        d += dt.timedelta(days=1)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01'])],
 [('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15'])],
 [('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31']),
  ('first monday via 1..7',
   ['2024-02-01', ['MO'], [1, 2, 3, 4, 5, 6, 7], 3],
   ['2024-02-05', '2024-03-04', '2024-04-01']),
  ('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13'])],
 [('sunday first of month', ['2024-01-01', ['SU'], [1], 2], ['2024-09-01', '2024-12-01']),
  ('tuesday 29th', ['2024-01-01', ['TU'], [29], 3], ['2024-10-29', '2025-04-29', '2025-07-29']),
  ('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01'])],
 [('weekday 15th',
   ['2024-03-01', ['MO', 'TU', 'WE', 'TH', 'FR'], [15], 4],
   ['2024-03-15', '2024-04-15', '2024-05-15', '2024-07-15']),
  ('thursday the 13th', ['2025-01-01', ['TH'], [13], 2], ['2025-02-13', '2025-03-13']),
  ('regression: friday the 13th',
   ['2024-01-01', ['FR'], [13], 3],
   ['2024-09-13', '2024-12-13', '2025-06-13']),
  ('last sunday via -1..-7',
   ['2024-01-01', ['SU'], [-1, -2, -3, -4, -5, -6, -7], 3],
   ['2024-01-28', '2024-02-25', '2024-03-31']),
  ('only bymonthday',
   ['2024-01-10', [], [1, 15], 4],
   ['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']),
  ('only byday',
   ['2024-01-01', ['SA', 'SU'], [], 4],
   ['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']),
  ('last day monday', ['2024-01-01', ['MO'], [-1], 2], ['2024-09-30', '2025-03-31'])]]
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: friday the 13th['2024-09-13', '2024-12-13', '2025-06-13']['2024-09-13', '2024-12-13', '2025-06-13']Passed
last sunday via -1..-7[]['2024-01-28', '2024-02-25', '2024-03-31']Failed
only bymonthday['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']['2024-01-15', '2024-02-01', '2024-02-15', '2024-03-01']Passed
only byday['2024-01-06', '2024-01-13', '2024-01-20', '2024-01-27']['2024-01-06', '2024-01-07', '2024-01-13', '2024-01-14']Failed
last day monday['2024-09-30', '2025-03-31']['2024-09-30', '2025-03-31']Passed
first monday via 1..7['2024-02-05', '2024-03-04', '2024-04-01']['2024-02-05', '2024-03-04', '2024-04-01']Passed
sunday first of month[]['2024-09-01', '2024-12-01']Failed

SHA-256 / fdabc3daa97d2564644b1e69ced7e82d1ed3d5a3d453e62da08322d6a51a6adc

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

Case digest / 08ff51477a2d56cb6b9e1824811e48a712a6e48cba61f762b13376f96cf03f07