secondsUntilUnix
Signature
Section titled “Signature”secondsUntilUnix(value: string | number, options?: { epochUnit?: UnixUnit; }): number | nullReturn the whole seconds from now until a stored Unix epoch, such as a JWT exp.
-
Rounded up to a whole second, so a wait of that length never falls short.
result <= 0means the target has been reached: it is RFC 7519 section 4.1.4’s test that the current time must be beforeexp. -
A past target gives a negative number, and
nullis invalid input only. Checknullfirst, then waitMath.max(0, n):Math.max(0, null)is 0, so an uncheckednullreads as “no wait”. -
valueis a safe integer or a digit string ("1813060920"); anything else returns null. A fractional epoch returns null, though RFC 7519 section 2 allows one: everyunix/function shares one integer grammar. CallMath.floor(exp)first, which can only end a token early, never late. -
No
timeZone: an instant has none. -
No leeway: RFC 7519 section 4.1.4 allows “some small leeway”, so add it where you test the result:
const left = secondsUntilUnix(exp, { epochUnit: "seconds" });const expired = left === null || left + leeway <= 0; -
Reads the clock once, after
valueandoptionsare checked. -
For “expires in 3 days”, once
leftis not null and above 0:formatHumanDuration(normalizeDuration(durationFromUnits({ seconds: left }), { largestUnit: "day" }),); // "3d" for 259200Without
normalizeDurationthe text is"259200s".
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | number | Unix epoch: a safe integer, or a string of optionally negative ASCII digits |
Options
Section titled “Options”options
optional: the unit value is counted in
| Option | Type | Default | Description |
|---|---|---|---|
epochUnit? | "seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit) | "milliseconds" | The unit value is counted in: "seconds" or "milliseconds", singular or plural; any other value returns null. The result is always in seconds. A seconds value read as the default milliseconds lands in 1970 and looks long past, so pass "seconds" for a JWT exp. |
Returns
Section titled “Returns”whole seconds until value, negative when it is past, or null for an invalid value or options or an epoch outside Temporal’s range
Related types
Section titled “Related types”Examples
Section titled “Examples”import { secondsUntilUnix } from "@northguild/gmt/unix/calculate";
secondsUntilUnix(1813060920, { epochUnit: "seconds" }) // 120 (two minutes after a clock at 1813060800)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.