BloombergLP::bdlt::DateUtil::addMonths

Return original advanced by numMonths, optionally preserving EOM.

Synopsis

Declared in <bdlt_dateutil.h>

static
Date
addMonths(
    Date const& original,
    int numMonths,
    bool eomFlag);

Description

Return the date that is the specified numMonths from the specified original date, adjusted as necessary according to the specified eomFlag (end-of-month flag). If eomFlag is true and original is the last day of the month, then adjust the result to be the last day of the month; if eomFlag is false, then no such adjustment is performed. In any case, if the day of the month in original does not exist in the month of the result (e.g., February 29, 2001), move the resulting date to the last day of the month. The behavior is undefined unless the operation results in a valid Date value. Note that numMonths may be negative.

Return Value

resulting date

Parameters

NameDescription
originalstarting date
numMonthsmonths to add (may be negative)
eomFlagwhether to preserve end-of-month when applicable