intervalFromDurationDate
Signature
Section titled “Signature”intervalFromDurationDate(value: string, duration: string, anchor: "start" | "end", options?: { overflow?: "reject" | "constrain" | undefined; }): { start: string; end: string; } | nullConstruct a date interval from a single point plus an ISO 8601 duration, anchored at either end.
anchor: "start"treatsvalueas the interval start and addsdurationto get the end.anchor: "end"treatsvalueas the interval end and subtractsdurationto get the start.- Uses
Temporal.PlainDate.prototype.add/.subtractsemantics, so calendar units (years/months/weeks) resolve againstvalueitself — no separaterelativeTois needed, unlikeaddDuration. Time units count as whole 24-hour days, as Temporal’s do. - A negative
duration(e.g."-P1D") can invert the computed span; returns null when that happens, mirroringintervalIntersectionDate’sstart > endrejection. - Accepts a RFC 9557 calendar-annotated PlainDate string — E5 (issue #78). The computed endpoint is resolved in
value’s own calendar (norelativeTo/pair-matching question, since there is only one calendar-tagged input) and both endpoints are re-formatted in that calendar, re-derived from the actual result rather than copied fromvalue’s tag (a leap-month or era boundary can fall between them). - Returns null on invalid input (unparseable
value, invalidduration, or ananchorother than"start"/"end").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string, optionally calendar-annotated |
duration | string | ISO 8601 duration string |
anchor | "start" | "end" | “start” | “end” — which endpoint value represents |
Options
Section titled “Options”options
How an out-of-range endpoint is handled
| Option | Type | Default | Description |
|---|---|---|---|
overflow? | "reject" | "constrain" (Overflow) | "constrain", Temporal’s default. | What to do when the computed endpoint is not a real date. "constrain" clamps it to the last valid day, so Jan 31 + 1 month is Feb 29 or 28; "reject" returns null. |
Returns
Section titled “Returns”{ start, end } with the constructed span, or null on invalid input
Members
| Member | Type | Description |
|---|---|---|
start | string | The date the interval begins on, as an ISO 8601 date (YYYY-MM-DD). It keeps a calendar annotation such as [u-ca=hebrew] when the inputs carry one. |
end | string | The first date after the interval, in the same format as start. It is exclusive: the interval holds everything from start up to but not including this value. It can equal start, which makes the interval empty. |
Related types
Section titled “Related types”Examples
Section titled “Examples”import { intervalFromDurationDate } from "@northguild/gmt/plain/interval";
intervalFromDurationDate("2024-01-01", "P1M", "start") // { start: "2024-01-01", end: "2024-02-01" }