Next Occurrences of a Recurring Event

medium
Unit 18 · Datetime II0/1 to milestone

Implement occurrences(start, rule, after, count) returning the next count ISO dates strictly after after for a recurring event starting on start (the start date itself is the first occurrence if it qualifies). rule is a dict:

  • {"freq": "daily", "interval": n}: every n days from start
  • {"freq": "weekly", "interval": n, "weekdays": [0, 2]}: on the listed weekdays (Monday = 0) of every n-th week, where weeks are counted from the Monday of the start date's week; days before start don't count
  • {"freq": "monthly", "interval": n}: the start date's day-of-month every n months; months that don't have that day are skipped
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Next Occurrences of a Recurring Event · TechGradify