subtractUnix
Signature
Section titled “Signature”subtractUnix(value: number, units: Partial<Record<DateTimeDurationUnit, number>>, options?: { epochUnit?: "seconds" | "milliseconds"; timeZone?: string; overflow?: Overflow; }): numberimport { subtractUnix } from "@northguild/gmt/unix/calculate";Subtract a temporal amount from a Unix epoch value and return the resulting epoch.
- Converts to ZonedDateTime, subtracts the duration, then converts back to epoch.
- Validates duration units and values.
- Returns null for invalid input.
overflow(“constrain” (default) | “reject”) controls out-of-range results, e.g. subtracting 1 month from Mar 31: “constrain” clamps to Feb 29/28, “reject” throws (resulting in null).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
number |
Unix timestamp (number) |
units |
Partial<Record<DateTimeDurationUnit, number>> |
Partial<Record<DateTimeDurationUnit, number>> object specifying units to subtract |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
epochUnit? |
"seconds" | "milliseconds" |
— |
timeZone? |
string |
— |
overflow? |
Overflow |
— |
Returns
Section titled “Returns”Unix epoch number after subtraction, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”subtractUnix(1706745600000, { days: 1 }) // 1706659200000subtractUnix(1706745600, { days: 1 }, { epochUnit: "seconds" }) // 1706659200subtractUnix(0, { days: 1 }) // -86400000 (Jan 1 1970 - 1 day = Dec 31 1969)