intervalFromDurationUnix
Signature
Section titled “Signature”intervalFromDurationUnix(value: string | number, duration: string, anchor: "start" | "end", options?: { epochUnit?: "seconds" | "milliseconds"; timeZone?: string; overflow?: Overflow; }): { start: number; end: number; }import { intervalFromDurationUnix } from "@northguild/gmt/unix/interval";Construct a Unix epoch 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.- Converts to
ZonedDateTime(system timeZone by default, consistent withaddUnix), adds/subtracts the duration there, then converts back to epoch — this is what lets calendar units (years/months/ weeks/days) resolve without arelativeTo: unlike a bareTemporal.Instant, theZonedDateTimesupplies its own implicit reference point. - A negative
duration(e.g."-P1D") can invert the computed span; returns null when that happens, mirroringintervalIntersectionUnix’sstart > endrejection. overflow(“constrain” (default) | “reject”) controls out-of-range results, e.g. adding 1 month to Jan 31: “constrain” clamps to Feb 29/28, “reject” returns null.- Returns null on invalid input (non-finite/non-integer
value, invalidduration, ananchorother than"start"/"end", or an invalid/unavailable timeZone).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string | number |
Unix epoch value (seconds or milliseconds) |
duration |
string |
ISO 8601 duration string |
anchor |
"start" | "end" |
“start” | “end” — which endpoint value represents |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
epochUnit? |
"seconds" | "milliseconds" |
— |
timeZone? |
string |
— |
overflow? |
Overflow |
— |
Returns
Section titled “Returns”{ start, end } with the constructed span (epoch numbers), or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”intervalFromDurationUnix(1704067200000, "P1D", "start", { timeZone: "UTC" }) // { start: 1704067200000, end: 1704153600000 }intervalFromDurationUnix(1704153600000, "P1D", "end", { timeZone: "UTC" }) // { start: 1704067200000, end: 1704153600000 }intervalFromDurationUnix(1706659200000, "P1M", "start", { timeZone: "UTC", overflow: "reject" }) // null (Jan 31 + 1 month overflows)intervalFromDurationUnix(1704067200000, "-P10D", "start", { timeZone: "UTC" }) // null (inverted span)intervalFromDurationUnix(NaN, "P1D", "start") // null