rollDate
Signature
Section titled “Signature”rollDate(value: string, convention: RollConvention, calendar: BusinessCalendar): stringMove a local date onto a working day according to convention.
-
Every industry answers “what if it lands on a non-working day” differently, so the convention is always explicit — there is no default.
Convention Behaviour followingForward to the next working day; a working day is left alone modifiedFollowingForward, unless that crosses into the next month, then backward precedingBackward to the previous working day; a working day is left alone modifiedPrecedingBackward, unless that crosses into the previous month, then forward endOfMonthThe last working day of value’s own month, wherever in the month it fallsnoneReturn valueunadjusted, working day or not -
followingandprecedingare on or after and on or before: they returnvalueitself when it is already a working day. For the strict neighbours usenextBusinessDayandpreviousBusinessDay. -
following,modifiedFollowingandprecedingare the three conventions ISDA 2006 Definitions §4.12(a) defines, in (i)–(iii), and match that text: (iii) reads “if ‘Preceding’ is specified, that date will be the first preceding day that is a Business Day”. §4.12(a) has no Modified Preceding;modifiedPrecedingfollows FpML’sBusinessDayConventionEnumMODPRECEDING: “adjusted to the first preceding day that is a business day unless that day falls in the previous calendar month, in which case … the first following day”.noneis what OpenGamma Strata callsNO_ADJUST. No TC39, ECMA or RFC standard governs them. -
endOfMonthis not an ISDA business-day convention, and not the industry “EOM rule”, which is a schedule rule: hold every date in a schedule to its month’s last day once the anchor is one. It is GMT’s primitive for building that rule. It always snaps to the last working day on or before the month’s final day, even from mid-month — leaving the month only if that whole month is closed, as a works shutdown would make it. A forward from a month-end anchor settles on the last working day of the target month, so the caller tests the anchor for month-end and applies this to the unadjusted target. Applied to a month-end date it agrees withmodifiedFollowing. -
valueandcalendar.holidaysare local dates;calendar.timeZoneis not read. A caller holding an instant reduces it to a local date first, withfloorToZone. -
Returns
""whenvalueis not a valid ISO PlainDate, whenconventionis not one GMT implements, whencalendaris not a validBusinessCalendar, and when the walk runs past 200,000 calendar days without finding a working day. Narrow the convention withisValidRollConventionto tell a misconfigured contract term apart from a bad date.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string to roll |
convention | RollConvention | RollConvention to apply |
calendar | BusinessCalendar | BusinessCalendar naming the weekend days and holidays |
Returns
Section titled “Returns”ISO PlainDate string of the rolled date, or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { rollDate } from "@northguild/gmt/calendar/business";
rollDate("2024-05-31", "following", { weekend: [6, 7], holidays: ["2024-05-31"], timeZone: "America/New_York" }) // "2024-06-03"