UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

35 lines (33 loc) • 1.36 kB
import { isOptionsArgument } from "../../internal/isObject.js"; import { compareUnixEpochs } from "../../internal/compareUnixEpochs.js"; // src/unix/compare/isBeforeUnix.ts /** * Return whether `value1` represents an instant strictly before `value2`. * * - Uses Temporal.Instant.compare to check ordering. * - Each value is a safe integer or a string of optionally negative ASCII digits; anything else * is invalid. * - Returns false if either input is invalid. * * @param value1 first unix epoch: a safe integer or a digit string * @param value2 second unix epoch, in the same unit * @param options optional: how both epochs are read * @returns `true` if `value1` is before `value2`, otherwise `false` * * @example isBeforeUnix(1704067200, 1706659200) // true * @example isBeforeUnix(1706659200, 1706659200) // false * @example isBeforeUnix(-1, 0) // true (1969-12-31T23:59:59.999Z is before 1970-01-01T00:00:00Z) * @example isBeforeUnix('invalid', 1704067200000) // false * @example isBeforeUnix(1704067200000, 'invalid') // false * @example isBeforeUnix("-1", "0") // true (digit strings) */ function isBeforeUnix(value1, value2, options) { try { if (!isOptionsArgument(options)) return false; const order = compareUnixEpochs(value1, value2, options); return order !== null && order === -1; } catch { return false; } } export { isBeforeUnix };