humanizeRecurrence function

String humanizeRecurrence(
  1. RecurrenceSpec spec
)

A short English phrase describing spec, e.g. "every 2 weeks on Tuesday".

The phrasing per frequency:

  • daily: "every day" / "every 2 days"
  • weekly: "weekly on Monday" / "every 2 weeks on Tuesday" (drops the "on …" when RecurrenceSpec.weekday is null)
  • monthly: "monthly on the 15th" (by RecurrenceSpec.monthDay) or "every 2nd Tuesday of the month" (by week-of-month + weekday)
  • yearly: "yearly on March 5" (by RecurrenceSpec.month + monthDay)

Example:

humanizeRecurrence(
  RecurrenceSpec(RecurrenceFrequency.weekly, interval: 2, weekday: DateTime.tuesday),
); // 'every 2 weeks on Tuesday'

Audited: 2026-06-12 11:26 EDT

Implementation

String humanizeRecurrence(RecurrenceSpec spec) {
  // Dispatch on frequency; each branch reads only the fields it needs.
  switch (spec.frequency) {
    case RecurrenceFrequency.daily:
      return _everyUnit(spec.interval, 'day', 'days');
    case RecurrenceFrequency.weekly:
      return _weekly(spec);
    case RecurrenceFrequency.monthly:
      return _monthly(spec);
    case RecurrenceFrequency.yearly:
      return _yearly(spec);
  }
}