broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if len(byday) == 5:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday')]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if byday == ['MO', 'TU', 'WE', 'TH', 'FR']:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday')]]
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)

prompt:
A five-day list including Saturday is rendered as "on weekdays".

House style: "every <unit>" for interval 1, else "every <n> <unit>s"; weekday lists are in Monday-first order without duplicates and joined as "A, B and C"; the exact set MO..FR renders as "on weekdays"; an ordinal renders "on the 2nd Tuesday", -1 as "on the last Friday" and -n (n>1) as "on the 2nd to last Friday"; count renders ", once" for 1 and ", <n> times" otherwise.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday))]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in byday]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

prompt:
BYDAY=MO,WE,FR is rendered as "Friday, Monday and Wednesday".

House style: "every <unit>" for interval 1, else "every <n> <unit>s"; weekday lists are in Monday-first order without duplicates and joined as "A, B and C"; the exact set MO..FR renders as "on weekdays"; an ordinal renders "on the 2nd Tuesday", -1 as "on the last Friday" and -n (n>1) as "on the 2nd to last Friday"; count renders ", once" for 1 and ", <n> times" otherwise.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (' and '.join(words))
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('once' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

prompt:
Three weekdays are rendered as "Monday and Wednesday and Friday".

House style: "every <unit>" for interval 1, else "every <n> <unit>s"; weekday lists are in Monday-first order without duplicates and joined as "A, B and C"; the exact set MO..FR renders as "on weekdays"; an ordinal renders "on the 2nd Tuesday", -1 as "on the last Friday" and -n (n>1) as "on the 2nd to last Friday"; count renders ", once" for 1 and ", <n> times" otherwise.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(freq, interval, byday, ordinal, count):
    unit = {'DAILY': 'day', 'WEEKLY': 'week', 'MONTHLY': 'month', 'YEARLY': 'year'}[freq]
    text = 'every ' + unit if interval == 1 else 'every %d %ss' % (interval, unit)
    names = {'MO': 'Monday', 'TU': 'Tuesday', 'WE': 'Wednesday', 'TH': 'Thursday', 'FR': 'Friday', 'SA': 'Saturday', 'SU': 'Sunday'}
    order = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
    def nth(n):
        return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n, 'th')
    if ordinal:
        word = ('last' if ordinal == -1 else nth(-ordinal) + ' to last') if ordinal < 0 else nth(ordinal)
        text += ' on the ' + word + ' ' + names[byday[0]]
    elif byday:
        if set(byday) == {'MO', 'TU', 'WE', 'TH', 'FR'}:
            text += ' on weekdays'
        else:
            words = [names[d] for d in sorted(set(byday), key=order.index)]
            text += ' on ' + (words[0] if len(words) == 1 else ', '.join(words[:-1]) + ' and ' + words[-1])
    if count:
        text += ', ' + ('1 time' if count == 1 else '%d times' % count)
    return text
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times')],
 [('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times'),
  ('second to last sunday', ['MONTHLY', 3, ['SU'], -2, 0], 'every 3 months on the 2nd to last Sunday'),
  ('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once')],
 [('second tuesday', ['MONTHLY', 1, ['TU'], 2, 10], 'every month on the 2nd Tuesday, 10 times'),
  ('weekdays exact', ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'FR'], 0, 0], 'every week on weekdays'),
  ('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years')],
 [('weekdays reordered',
   ['WEEKLY', 1, ['FR', 'MO', 'TU', 'WE', 'TH'], 0, 3],
   'every week on weekdays, 3 times'),
  ('five days with saturday',
   ['WEEKLY', 1, ['MO', 'TU', 'WE', 'TH', 'SA'], 0, 0],
   'every week on Monday, Tuesday, Wednesday, Thursday and Saturday'),
  ('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday')],
 [('duplicate days', ['WEEKLY', 3, ['SU', 'MO', 'SU'], 0, 2], 'every 3 weeks on Monday and Sunday, 2 times'),
  ('daily with count one', ['DAILY', 1, [], 0, 1], 'every day, once'),
  ('yearly interval', ['YEARLY', 4, [], 0, 0], 'every 4 years'),
  ('two days unordered', ['WEEKLY', 1, ['TH', 'TU'], 0, 1], 'every week on Tuesday and Thursday, once'),
  ('regression: weekly three days',
   ['WEEKLY', 1, ['MO', 'WE', 'FR'], 0, 0],
   'every week on Monday, Wednesday and Friday'),
  ('biweekly single day once', ['WEEKLY', 2, ['TU'], 0, 1], 'every 2 weeks on Tuesday, once'),
  ('last friday monthly', ['MONTHLY', 1, ['FR'], -1, 6], 'every month on the last Friday, 6 times')]]
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)

prompt:
COUNT=1 is rendered as "1 times".

House style: "every <unit>" for interval 1, else "every <n> <unit>s"; weekday lists are in Monday-first order without duplicates and joined as "A, B and C"; the exact set MO..FR renders as "on weekdays"; an ordinal renders "on the 2nd Tuesday", -1 as "on the last Friday" and -n (n>1) as "on the 2nd to last Friday"; count renders ", once" for 1 and ", <n> times" otherwise.

split: open-access


broken_source:
"""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 < 0:
        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) + 1
        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'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None)],
 [('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'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None)]]
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)

source:
"""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 == 0:
        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) + 1
        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'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None)],
 [('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'),
  ('count zero', ['2024-01-01', 1, [0], 0, 0], None),
  ('count negative', ['2024-01-01', 2, [0, 3], 0, -1], None)]]
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)

prompt:
COUNT=0 reports a final date although the series is empty.

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.

split: open-access


broken_source:
"""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 >= start.weekday()]
    if count <= len(first_week):
        w = first_week[count - 1]
        weeks = 0
    else:
        rest = count - len(first_week)
        weeks = (rest - 1) // len(days) + 1
        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')],
 [('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')]]
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)

source:
"""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) + 1
        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')],
 [('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')]]
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)

prompt:
With WKST=SU a Sunday in the first week is miscounted and the end date shifts by a week.

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.

split: open-access


broken_source:
"""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)

source:
"""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)

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

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.

split: open-access


broken_source:
"""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) + 1
        w = days[rest % 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),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23')],
 [('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')],
 [('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')]]
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)

source:
"""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) + 1
        w = days[(rest - 1) % len(first_week or 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),
  ('WKST=SU weekend', ['2024-03-09', 1, [5, 6], 6, 5], '2024-03-23')],
 [('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')],
 [('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')]]
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)

prompt:
The final weekday is one position too late in the week pattern.

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.

split: open-access


broken_source:
"""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) + 1
        w = days[(rest - 1) % len(days)]
    last = week0 + dt.timedelta(days=weeks * 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')],
 [('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')]]
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)

source:
"""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) + 1
        w = days[(rest - 1) % len(days)]
    last = week0 + dt.timedelta(days=(weeks + interval - 1) * 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')],
 [('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')]]
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)

prompt:
An every-other-week series reports an end date halfway through the real series.

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.

split: open-access


prompt:
An override for a date before the series start survives the edit as a phantom exception.

An all-day series (old_start, interval, count) is edited to start at new_start with new_interval. Each override [original, target] (target None = cancelled) is keyed by occurrence index i, where original = old_start + i*interval; overrides not on an old instance (before the series, misaligned or at i >= count) are dropped. The override is re-keyed to new_start + i*new_interval; moved targets are absolute and kept unchanged; an override whose target equals its new key is dropped as a no-op; the last override for a key wins. Return [[new_key, target]] sorted by new key.

split: open-access


prompt:
After changing weekly to every-two-weeks, exceptions attach to the wrong occurrences.

An all-day series (old_start, interval, count) is edited to start at new_start with new_interval. Each override [original, target] (target None = cancelled) is keyed by occurrence index i, where original = old_start + i*interval; overrides not on an old instance (before the series, misaligned or at i >= count) are dropped. The override is re-keyed to new_start + i*new_interval; moved targets are absolute and kept unchanged; an override whose target equals its new key is dropped as a no-op; the last override for a key wins. Return [[new_key, target]] sorted by new key.

split: open-access


prompt:
A moved instance whose target now coincides with its new slot is kept as a redundant exception, and a former no-op is dropped although it now moves the instance.

An all-day series (old_start, interval, count) is edited to start at new_start with new_interval. Each override [original, target] (target None = cancelled) is keyed by occurrence index i, where original = old_start + i*interval; overrides not on an old instance (before the series, misaligned or at i >= count) are dropped. The override is re-keyed to new_start + i*new_interval; moved targets are absolute and kept unchanged; an override whose target equals its new key is dropped as a no-op; the last override for a key wins. Return [[new_key, target]] sorted by new key.

split: open-access


prompt:
Instances that were explicitly rescheduled to a fixed date are shifted along with the series.

An all-day series (old_start, interval, count) is edited to start at new_start with new_interval. Each override [original, target] (target None = cancelled) is keyed by occurrence index i, where original = old_start + i*interval; overrides not on an old instance (before the series, misaligned or at i >= count) are dropped. The override is re-keyed to new_start + i*new_interval; moved targets are absolute and kept unchanged; an override whose target equals its new key is dropped as a no-op; the last override for a key wins. Return [[new_key, target]] sorted by new key.

split: open-access


prompt:
Exceptions are returned in edit order, not by occurrence.

An all-day series (old_start, interval, count) is edited to start at new_start with new_interval. Each override [original, target] (target None = cancelled) is keyed by occurrence index i, where original = old_start + i*interval; overrides not on an old instance (before the series, misaligned or at i >= count) are dropped. The override is re-keyed to new_start + i*new_interval; moved targets are absolute and kept unchanged; an override whose target equals its new key is dropped as a no-op; the last override for a key wins. Return [[new_key, target]] sorted by new key.

split: open-access