[#BloombergLP-bdlt-CalendarUtil] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlt.adoc[bdlt]::CalendarUtil :relfileprefix: ../../ :mrdocs: This `struct` provides a namespace for utility functions that operate on dates in the context of supplied calendars. == Synopsis Declared in `<bdlt_calendarutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- struct CalendarUtil; ---- == Enums [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlt/CalendarUtil/ShiftConvention.adoc[`ShiftConvention`] | Enumeration used to delineate various date‐shifting conventions. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlt/CalendarUtil/addBusinessDaysIfValid.adoc[`addBusinessDaysIfValid`] | Load, into the specified `result`, the date that is the specified `numBusinessDays` chronologically after the specified `original` date according to the specified `calendar`. The resulting date is chronologically before the `original` date for negative values of `numBusinessDays`, the chronologically earliest business day that is on or after the `original` date for `0 == numBusinessDays`, and chronologically after the `original` date for positive values of `numBusinessDays`. Return 0 on success, and a non‐zero value, without modifying `*result`, if either the `original` date or the resulting date is not within the valid range of `calendar`. Note that if `0 != numBusinessDays`, then the result of `addBusinessDaysIfValid(res, orig, cal, numBusinessDays)` is identical to the result of `subtractBusinessDaysIfValid(res, orig, cal, ‐numBusinessDays)`. | xref:BloombergLP/bdlt/CalendarUtil/nthBusinessDayOfMonthOrMaxIfValid.adoc[`nthBusinessDayOfMonthOrMaxIfValid`] | Load, into the specified `result`, the date corresponding to the specified `n`th 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`. | xref:BloombergLP/bdlt/CalendarUtil/shiftFollowingIfValid.adoc[`shiftFollowingIfValid`] | Load, into the specified `result`, the date of the chronologically earliest business day that is on or after the specified `original` date based on the specified `calendar`. Return 0 on success, and a non‐zero value, without modifying `*result`, if the `original` date is not within the valid range of `calendar` or the following business day cannot be found within the valid range of `calendar`. | xref:BloombergLP/bdlt/CalendarUtil/shiftIfValid-0df.adoc[`shiftIfValid`] | `shiftIfValid` overloads | xref:BloombergLP/bdlt/CalendarUtil/shiftModifiedFollowingIfValid.adoc[`shiftModifiedFollowingIfValid`] | Load, into the specified `result`, the date of the chronologically earliest business day that is on or after the specified `original` date, unless a date cannot be found in the same month, in which case load the chronologically latest business day before the `original` date based on the specified `calendar`. Return 0 on success, and a non‐zero value, without modifying `*result`, if the `original` date is not within the valid range of `calendar` or a valid business date cannot be found according to the above algorithm within the valid range of `calendar`. | xref:BloombergLP/bdlt/CalendarUtil/shiftModifiedPrecedingIfValid.adoc[`shiftModifiedPrecedingIfValid`] | Load, into the specified `result`, the date of the chronologically latest business day that is on or before the specified `original` date, unless a date cannot be found in the same month, in which case load the chronologically earliest business day after the `original` date based on the specified `calendar`. Return 0 on success, and a non‐zero value, without modifying `*result`, if the `original` date is not within the valid range of `calendar` or a valid business date cannot be found according to the above algorithm within the valid range of `calendar`. | xref:BloombergLP/bdlt/CalendarUtil/shiftPrecedingIfValid.adoc[`shiftPrecedingIfValid`] | Load, into the specified `result`, the date of the chronologically latest business day that is on or before the specified `original` date based on the specified `calendar`. Return 0 on success, and a non‐zero value, without modifying `*result`, if the `original` date is not within the valid range of `calendar` or the preceding business day cannot be found within the valid range of `calendar`. | xref:BloombergLP/bdlt/CalendarUtil/subtractBusinessDaysIfValid.adoc[`subtractBusinessDaysIfValid`] | Load, into the specified `result`, the date that is the specified `numBusinessDays` chronologically before the specified `original` date according to the specified `calendar`. The resulting date is chronologically before the `original` date for positive values of `numBusinessDays`, the chronologically latest business day that is on or before the `original` date for `0 == numBusinessDays`, and chronologically after the `original` date for negative values of `numBusinessDays`. Return 0 on success, and a non‐zero value, without modifying `*result`, if either the `original` date or the resulting date is not within the valid range of `calendar`. Note that if `0 != numBusinessDays`, then the result of `subtractBusinessDaysIfValid(res, orig, cal, numBusinessDays)` is identical to the result of `addBusinessDaysIfValid(res, orig, cal, ‐numBusinessDays)`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#