getUnixAgo
Signature
Section titled “Signature”getUnixAgo(units: Partial<Record<keyof DurationLike, number>>, options?: { epochUnit?: UnixUnit; }): number | nullReturn the Unix epoch before now, counted from the current time in UTC.
- Reads the clock once, after
unitsandoptionsare checked. unitsis an object of unit amounts, such as{ days: 90 }. A duration string returns null, and so does a fractional amount: write{ hours: 36 }for a day and a half.- Lengths are unsigned: a negative amount returns null.
getUnixIncounts forward. { days: 0 }is a valid length and gives now.- Calendar units count in UTC, so the result does not change with the server’s zone, and a missing day clamps to the end of the month, as
subtractUnixdoes. For another zone’s wall clock, usegetZonedAgoand convert. - A
timeZonemember is not read, asgetUnixNowreads none. - Each call reads the clock. To pin the start, use
subtractUnix(getUnixNow(), units).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
units | Partial<Record<keyof DurationLike, number>> | unit amounts, such as { days: 90 }; never negative |
Options
Section titled “Options”options
optional: the unit of the result
| Option | Type | Default | Description |
|---|---|---|---|
epochUnit? | "seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit) | "milliseconds" | The unit of the returned epoch: "seconds" or "milliseconds", singular or plural. Any other value returns null. Seconds floor toward −∞, and a JWT exp needs them: the default is milliseconds, and a millisecond exp reads as a date far in the future. |
Returns
Section titled “Returns”the Unix epoch, or null for invalid units, a negative amount, invalid options or a result outside Temporal’s range
Related types
Section titled “Related types”Examples
Section titled “Examples”import { getUnixAgo } from "@northguild/gmt/unix/get";
getUnixAgo({ days: 90 }, { epochUnit: "seconds" }) // 1805284800 (90 days back, from a clock at 2027-06-15T12:00:00Z)Source
Section titled “Source”Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else:© 2026 NorthGuild, all rights reserved.