@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.
34 lines (32 loc) • 1.29 kB
JavaScript
import { isOptionsArgument } from "../../internal/isObject.js";
import { compareUnixEpochs } from "../../internal/compareUnixEpochs.js";
// src/unix/compare/isAfterUnix.ts
/**
* Return whether `value1` represents an instant strictly after `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 after `value2`, otherwise `false`
*
* @example isAfterUnix(1706659200, 1704067200) // true
* @example isAfterUnix(1706659200, 1706659200) // false
* @example isAfterUnix(-1, 0) // false
* @example isAfterUnix("1706659200", "1704067200") // true (digit strings)
* @example isAfterUnix(" 1706659200", 1704067200) // false (a padded string is not an epoch)
*/
function isAfterUnix(value1, value2, options) {
try {
if (!isOptionsArgument(options)) return false;
const order = compareUnixEpochs(value1, value2, options);
return order !== null && order === 1;
} catch {
return false;
}
}
export { isAfterUnix };