{"abstract":"The second Tuesday is computed on the wrong date in months that do not begin on Tuesday.","category":"Calendar recurrence rules","checks":7,"contract":"FREQ=MONTHLY;BYDAY=<ordinal><weekday>. weekday is 0=Monday..6=Sunday; ordinal 1..5 counts from the start of the month and -1..-5 from the end. A month lacking that occurrence is skipped and does not consume COUNT. Months step by interval from the dtstart month; instances before dtstart are dropped. Return the first count ISO dates.","contract_signature":"dtstart, interval, ordinal, weekday, count","evaluation_group":"w2-calendar-recurrence-rules-monthly-nth-weekday","failed_approach":"The partial repair `abs(weekday - first_wd)` drops the modulo and so goes wrong whenever the first weekday of the month is after the target.","family":"w2-calendar-recurrence-rules-monthly-nth-weekday-first-offset","id":"FA-76891","implementations":{"attempt":{"sha256":"617f07b24cfdf5c7669f6ed19c434ca6e81df8ff05c55d1b1c2a6341ca01bcff","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport datetime as dt\nimport calendar\nN = 1\nobservations = []\ndef solve(dtstart, interval, ordinal, weekday, count):\n    start = dt.date.fromisoformat(dtstart)\n    out = []\n    for k in range(600):\n        if len(out) >= count:\n            return out\n        mi = start.month - 1 + k * interval\n        y, m = start.year + mi // 12, mi % 12 + 1\n        dim = calendar.monthrange(y, m)[1]\n        first_wd = dt.date(y, m, 1).weekday()\n        last_wd = dt.date(y, m, dim).weekday()\n        if ordinal > 0:\n            day = 1 + abs(weekday - first_wd) + 7 * (ordinal - 1)\n        else:\n            day = dim - (last_wd - weekday) % 7 + 7 * (ordinal + 1)\n        if day < 1 or day > dim:\n            continue\n        d = dt.date(y, m, day)\n        if d < start:\n            continue\n        out.append(d.isoformat())\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09']),\n  ('last friday', ['2024-01-01', 1, -1, 4, 4], ['2024-01-26', '2024-02-23', '2024-03-29', '2024-04-26']),\n  ('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19']),\n  ('fifth monday skips months', ['2024-01-01', 1, 5, 0, 3], ['2024-01-29', '2024-04-29', '2024-07-29']),\n  ('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05'])],\n [('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19']),\n  ('fifth monday skips months', ['2024-01-01', 1, 5, 0, 3], ['2024-01-29', '2024-04-29', '2024-07-29']),\n  ('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25'])],\n [('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], [])],\n [('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], []),\n  ('fifth friday interval 1',\n   ['2024-02-01', 1, 5, 4, 4],\n   ['2024-03-29', '2024-05-31', '2024-08-30', '2024-11-29']),\n  ('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09'])],\n [('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], []),\n  ('fifth friday interval 1',\n   ['2024-02-01', 1, 5, 4, 4],\n   ['2024-03-29', '2024-05-31', '2024-08-30', '2024-11-29']),\n  ('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09']),\n  ('last friday', ['2024-01-01', 1, -1, 4, 4], ['2024-01-26', '2024-02-23', '2024-03-29', '2024-04-26']),\n  ('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19'])]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"4c42957ae5f0fdd6fd9e604b24c813f0721e550c0af14e537f0b484e715f25b0","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nimport datetime as dt\nimport calendar\nN = 1\nobservations = []\ndef solve(dtstart, interval, ordinal, weekday, count):\n    start = dt.date.fromisoformat(dtstart)\n    out = []\n    for k in range(600):\n        if len(out) >= count:\n            return out\n        mi = start.month - 1 + k * interval\n        y, m = start.year + mi // 12, mi % 12 + 1\n        dim = calendar.monthrange(y, m)[1]\n        first_wd = dt.date(y, m, 1).weekday()\n        last_wd = dt.date(y, m, dim).weekday()\n        if ordinal > 0:\n            day = 1 + (first_wd - weekday) % 7 + 7 * (ordinal - 1)\n        else:\n            day = dim - (last_wd - weekday) % 7 + 7 * (ordinal + 1)\n        if day < 1 or day > dim:\n            continue\n        d = dt.date(y, m, day)\n        if d < start:\n            continue\n        out.append(d.isoformat())\n    return out\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09']),\n  ('last friday', ['2024-01-01', 1, -1, 4, 4], ['2024-01-26', '2024-02-23', '2024-03-29', '2024-04-26']),\n  ('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19']),\n  ('fifth monday skips months', ['2024-01-01', 1, 5, 0, 3], ['2024-01-29', '2024-04-29', '2024-07-29']),\n  ('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05'])],\n [('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19']),\n  ('fifth monday skips months', ['2024-01-01', 1, 5, 0, 3], ['2024-01-29', '2024-04-29', '2024-07-29']),\n  ('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25'])],\n [('fifth-to-last thursday', ['2024-01-01', 1, -5, 3, 3], ['2024-02-01', '2024-05-02', '2024-08-01']),\n  ('interval 2 first saturday',\n   ['2024-11-01', 2, 1, 5, 4],\n   ['2024-11-02', '2025-01-04', '2025-03-01', '2025-05-03']),\n  ('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], [])],\n [('first-month occurrence before dtstart',\n   ['2024-03-20', 1, 1, 2, 3],\n   ['2024-04-03', '2024-05-01', '2024-06-05']),\n  ('third wednesday quarterly',\n   ['2023-12-01', 3, 3, 2, 4],\n   ['2023-12-20', '2024-03-20', '2024-06-19', '2024-09-18']),\n  ('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], []),\n  ('fifth friday interval 1',\n   ['2024-02-01', 1, 5, 4, 4],\n   ['2024-03-29', '2024-05-31', '2024-08-30', '2024-11-29']),\n  ('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09'])],\n [('fourth sunday', ['2025-02-10', 1, 4, 6, 4], ['2025-02-23', '2025-03-23', '2025-04-27', '2025-05-25']),\n  ('last monday dtstart on it', ['2024-05-27', 1, -1, 0, 3], ['2024-05-27', '2024-06-24', '2024-07-29']),\n  ('count zero', ['2024-01-01', 1, 1, 0, 0], []),\n  ('fifth friday interval 1',\n   ['2024-02-01', 1, 5, 4, 4],\n   ['2024-03-29', '2024-05-31', '2024-08-30', '2024-11-29']),\n  ('regression: second tuesday',\n   ['2024-01-01', 1, 2, 1, 4],\n   ['2024-01-09', '2024-02-13', '2024-03-12', '2024-04-09']),\n  ('last friday', ['2024-01-01', 1, -1, 4, 4], ['2024-01-26', '2024-02-23', '2024-03-29', '2024-04-26']),\n  ('second to last sunday',\n   ['2024-02-01', 1, -2, 6, 4],\n   ['2024-02-18', '2024-03-24', '2024-04-21', '2024-05-19'])]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(*args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"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.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-calendar-recurrence-rules-monthly-nth-weekday-first-offset","generated_at":"2026-09-29T14:49:20.626801+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Recurring calendar series are expanded into concrete instances for display, reminders and conflict checks.","root_cause":"The offset from the first of the month to the target weekday is subtracted in the wrong direction.","sha256":"24d899bc38a4bb423ea66a048a7df72b99ab1ec85472cf00e6e56814d32c5bfd","title":"Monthly ordinal BYDAY such as 2TU or -1FR: first offset · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verified":true,"visibility":"public","verification":{"attempt":{"elapsed_ms":38.654,"exit_code":1,"observations":[{"actual":["2024-01-09","2024-02-10","2024-03-11","2024-04-09"],"check":"regression: second tuesday","expected":["2024-01-09","2024-02-13","2024-03-12","2024-04-09"],"passed":false},{"actual":["2024-01-26","2024-02-23","2024-03-29","2024-04-26"],"check":"last friday","expected":["2024-01-26","2024-02-23","2024-03-29","2024-04-26"],"passed":true},{"actual":["2024-02-18","2024-03-24","2024-04-21","2024-05-19"],"check":"second to last sunday","expected":["2024-02-18","2024-03-24","2024-04-21","2024-05-19"],"passed":true},{"actual":["2024-01-29","2024-04-29","2024-05-31"],"check":"fifth monday skips months","expected":["2024-01-29","2024-04-29","2024-07-29"],"passed":false},{"actual":["2024-02-01","2024-05-02","2024-08-01"],"check":"fifth-to-last thursday","expected":["2024-02-01","2024-05-02","2024-08-01"],"passed":true},{"actual":["2024-11-02","2025-01-04","2025-03-01","2025-05-03"],"check":"interval 2 first saturday","expected":["2024-11-02","2025-01-04","2025-03-01","2025-05-03"],"passed":true},{"actual":["2024-04-03","2024-05-01","2024-06-04"],"check":"first-month occurrence before dtstart","expected":["2024-04-03","2024-05-01","2024-06-05"],"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: second tuesday\", \"actual\": [\"2024-01-09\", \"2024-02-10\", \"2024-03-11\", \"2024-04-09\"], \"expected\": [\"2024-01-09\", \"2024-02-13\", \"2024-03-12\", \"2024-04-09\"], \"passed\": false}, {\"check\": \"last friday\", \"actual\": [\"2024-01-26\", \"2024-02-23\", \"2024-03-29\", \"2024-04-26\"], \"expected\": [\"2024-01-26\", \"2024-02-23\", \"2024-03-29\", \"2024-04-26\"], \"passed\": true}, {\"check\": \"second to last sunday\", \"actual\": [\"2024-02-18\", \"2024-03-24\", \"2024-04-21\", \"2024-05-19\"], \"expected\": [\"2024-02-18\", \"2024-03-24\", \"2024-04-21\", \"2024-05-19\"], \"passed\": true}, {\"check\": \"fifth monday skips months\", \"actual\": [\"2024-01-29\", \"2024-04-29\", \"2024-05-31\"], \"expected\": [\"2024-01-29\", \"2024-04-29\", \"2024-07-29\"], \"passed\": false}, {\"check\": \"fifth-to-last thursday\", \"actual\": [\"2024-02-01\", \"2024-05-02\", \"2024-08-01\"], \"expected\": [\"2024-02-01\", \"2024-05-02\", \"2024-08-01\"], \"passed\": true}, {\"check\": \"interval 2 first saturday\", \"actual\": [\"2024-11-02\", \"2025-01-04\", \"2025-03-01\", \"2025-05-03\"], \"expected\": [\"2024-11-02\", \"2025-01-04\", \"2025-03-01\", \"2025-05-03\"], \"passed\": true}, {\"check\": \"first-month occurrence before dtstart\", \"actual\": [\"2024-04-03\", \"2024-05-01\", \"2024-06-04\"], \"expected\": [\"2024-04-03\", \"2024-05-01\", \"2024-06-05\"], \"passed\": false}], \"passed\": false}\n"},"broken":{"elapsed_ms":42.255,"exit_code":1,"observations":[{"actual":["2024-01-14","2024-02-10","2024-03-11","2024-04-14"],"check":"regression: second tuesday","expected":["2024-01-09","2024-02-13","2024-03-12","2024-04-09"],"passed":false},{"actual":["2024-01-26","2024-02-23","2024-03-29","2024-04-26"],"check":"last friday","expected":["2024-01-26","2024-02-23","2024-03-29","2024-04-26"],"passed":true},{"actual":["2024-02-18","2024-03-24","2024-04-21","2024-05-19"],"check":"second to last sunday","expected":["2024-02-18","2024-03-24","2024-04-21","2024-05-19"],"passed":true},{"actual":["2024-01-29","2024-04-29","2024-05-31"],"check":"fifth monday skips months","expected":["2024-01-29","2024-04-29","2024-07-29"],"passed":false},{"actual":["2024-02-01","2024-05-02","2024-08-01"],"check":"fifth-to-last thursday","expected":["2024-02-01","2024-05-02","2024-08-01"],"passed":true},{"actual":["2024-11-07","2025-01-05","2025-03-01","2025-05-06"],"check":"interval 2 first saturday","expected":["2024-11-02","2025-01-04","2025-03-01","2025-05-03"],"passed":false},{"actual":["2024-04-06","2024-05-01","2024-06-04"],"check":"first-month occurrence before dtstart","expected":["2024-04-03","2024-05-01","2024-06-05"],"passed":false}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: second tuesday\", \"actual\": [\"2024-01-14\", \"2024-02-10\", \"2024-03-11\", \"2024-04-14\"], \"expected\": [\"2024-01-09\", \"2024-02-13\", \"2024-03-12\", \"2024-04-09\"], \"passed\": false}, {\"check\": \"last friday\", \"actual\": [\"2024-01-26\", \"2024-02-23\", \"2024-03-29\", \"2024-04-26\"], \"expected\": [\"2024-01-26\", \"2024-02-23\", \"2024-03-29\", \"2024-04-26\"], \"passed\": true}, {\"check\": \"second to last sunday\", \"actual\": [\"2024-02-18\", \"2024-03-24\", \"2024-04-21\", \"2024-05-19\"], \"expected\": [\"2024-02-18\", \"2024-03-24\", \"2024-04-21\", \"2024-05-19\"], \"passed\": true}, {\"check\": \"fifth monday skips months\", \"actual\": [\"2024-01-29\", \"2024-04-29\", \"2024-05-31\"], \"expected\": [\"2024-01-29\", \"2024-04-29\", \"2024-07-29\"], \"passed\": false}, {\"check\": \"fifth-to-last thursday\", \"actual\": [\"2024-02-01\", \"2024-05-02\", \"2024-08-01\"], \"expected\": [\"2024-02-01\", \"2024-05-02\", \"2024-08-01\"], \"passed\": true}, {\"check\": \"interval 2 first saturday\", \"actual\": [\"2024-11-07\", \"2025-01-05\", \"2025-03-01\", \"2025-05-06\"], \"expected\": [\"2024-11-02\", \"2025-01-04\", \"2025-03-01\", \"2025-05-03\"], \"passed\": false}, {\"check\": \"first-month occurrence before dtstart\", \"actual\": [\"2024-04-06\", \"2024-05-01\", \"2024-06-04\"], \"expected\": [\"2024-04-03\", \"2024-05-01\", \"2024-06-05\"], \"passed\": false}], \"passed\": false}\n"}},"member_only":{"stages":["fixed"],"fields":["implementations.fixed","verification.fixed","harness","repair"],"note":"The verified repair, its recorded checks, the repair description, and the scoring harness are available to members."}}