BloombergLP::bdlt::CalendarUtil::nthBusinessDayOfMonthOrMaxIfValid

Load the nth business day of a month, or the furthest available.

Synopsis

Declared in <bdlt_calendarutil.h>

static
int
nthBusinessDayOfMonthOrMaxIfValid(
    bdlt::Date* result,
    bdlt::Calendar const& calendar,
    int year,
    int month,
    int n);

Description

Load, into the specified result, the date corresponding to the specified nth business day of the specified month and the specified year based on the specified calendar. A positive value of n indicates that counting the number of business days begins from the first calendar date of the month (inclusive), and a negative value of n indicates that counting the number of business days begins from the last calendar date of the month (inclusive). If there are fewer than abs(n) business days in the month according to the calendar, the business day furthest from the first date of the month is chosen if n > 0, and the business day furthest from the last date of the month is chosen if n < 0. Return 0 on success, and a non-zero value, without modifying *result, if the entire month specified by year and month is not within the valid range of the calendar or there are no business days in the month specified by year and month. The behavior is undefined unless n != 0, 1 <= year <= 9999, and 1 <= month <= 12.

Return Value

0 on success, non-zero on failure

Parameters

NameDescription
resultdestination for the resulting date
calendarcalendar used for business-day determination
yearcalendar year
monthmonth of year in [1 .. 12]
nwhich business day to select (non-zero; negative counts from end)