Skip to main content

nth_weekday

Function nth_weekday 

pub fn nth_weekday(
    n: u32,
    weekday: DayOfWeek,
    year: i32,
    month: u32,
) -> Option<NaiveDate>
Expand description

The nth occurrence of weekday in (year, month), counting from one.

None when the month does not contain an nth such day — every month holds four of each weekday and some hold a fifth, so nth_weekday(5, ..) is a question with a real negative answer rather than an error. None also reports an n of zero or a (year, month) outside the Gregorian range.

This is the general form of the arithmetic the roll families are written in: an IMM date is the third Wednesday of its cycle month, and an FRN roll the third of the month. Callers wanting a business day should adjust the result — this function is calendar-blind.