Return the n`th `dayOfWeek in the given month and year.

Synopsis

Declared in <bdlt_dateutil.h>

static
Date
nthDayOfWeekInMonth(
    int year,
    int month,
    DayOfWeek::Enum dayOfWeek,
    int n);

Description

Return the date in the specified month of the specified year corresponding to the specified n`th occurrence of the specified `dayOfWeek. If n < 0, return the date corresponding to the ‐n`th occurrence of the `dayOfWeek counting from the end of the month towards the first of the month. If 5 == n and a result cannot be found in month, then return the date of the first dayOfWeek in the following month. If ‐5 == n and a result cannot be found in month, then return the date of the last dayOfWeek in the previous month. The behavior is undefined unless 1 <= year <= 9999, 1 <= month <= 12, n != 0, ‐5 <= n <= 5, and the resulting date is neither earlier than 0001/01/01 nor later than 9999/12/31.

For example: ` nthDayOfWeekInMonth(2004, 11, DayOfWeek::e_THURSDAY, 4); ` returns November 25, 2004, the fourth Thursday in November, 2004.

Return Value

matching date

Parameters

Name

Description

year

calendar year

month

month of year in [1 .. 12]

dayOfWeek

desired day of week

n

which occurrence to select (non‐zero; negative counts from end)

Created with MrDocs