[#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&period;

== Synopsis

Declared in `&lt;bdlt&lowbar;calendarutil&period;h&gt;`

[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&hyphen;shifting conventions&period;
|===


== 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`&period; 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 &equals;&equals; numBusinessDays`, and chronologically after the `original` date for positive values of `numBusinessDays`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;result`, if either the `original` date or the resulting date is not within the valid range of `calendar`&period; Note that if `0 !&equals; numBusinessDays`, then the result of `addBusinessDaysIfValid(res, orig, cal, numBusinessDays)` is identical to the result of `subtractBusinessDaysIfValid(res, orig, cal, &hyphen;numBusinessDays)`&period;
| 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`&period; 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)&period; 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 &gt; 0`, and the business day furthest from the last date of the month is chosen if `n &lt; 0`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;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`&period; The behavior is undefined unless `n !&equals; 0`, `1 &lt;&equals; year &lt;&equals; 9999`, and `1 &lt;&equals; month &lt;&equals; 12`&period;
| 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`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;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`&period;
| 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`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;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`&period;
| 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`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;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`&period;
| 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`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;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`&period;
| 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`&period; 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 &equals;&equals; numBusinessDays`, and chronologically after the `original` date for negative values of `numBusinessDays`&period; Return 0 on success, and a non&hyphen;zero value, without modifying `&ast;result`, if either the `original` date or the resulting date is not within the valid range of `calendar`&period; Note that if `0 !&equals; numBusinessDays`, then the result of `subtractBusinessDaysIfValid(res, orig, cal, numBusinessDays)` is identical to the result of `addBusinessDaysIfValid(res, orig, cal, &hyphen;numBusinessDays)`&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
