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.

36 lines (34 loc) • 1.55 kB
import { isOptionsArgument } from "../../internal/isObject.js"; import { compareUnixEpochs } from "../../internal/compareUnixEpochs.js"; // src/unix/compare/areUnixEqual.ts /** * Return whether `value1` and `value2` represent the same instant. * * - Uses Temporal.Instant.compare to check equality. * - 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` and `value2` are equal, otherwise `false` * * @example areUnixEqual(1706659200, 1706659200) // true * @example areUnixEqual(1706659200, 1704067200) // false * @example areUnixEqual(1706659200, 1706659200000, { epochUnit: "seconds" }) // false (epochUnit applies to both values) * @example areUnixEqual(1706659200, 1706659200000) // false * @example areUnixEqual(-86400000, 0) // false (1969-12-31 is not equal to 1970-01-01) * @example areUnixEqual("1706659200", 1706659200, { epochUnit: "second" }) // true (a digit string is the same epoch) * @example areUnixEqual("1706659200.0", 1706659200) // false (not a digit string) */ function areUnixEqual(value1, value2, options) { try { if (!isOptionsArgument(options)) return false; const order = compareUnixEpochs(value1, value2, options); return order !== null && order === 0; } catch { return false; } } export { areUnixEqual };