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.

52 lines • 2.42 kB
import { UnixUnit } from "../validate/isValidUnixUnit.js"; /** * Return true when the Unix timestamp is between start and end (inclusive by default). * * - Uses Temporal.Instant.compare for comparison. * - Returns false if start > end or inputs are invalid. * - Each value is a safe integer or a digit string (`"1705000000000"`); anything else returns false. * * @param value Unix epoch to check: a safe integer, or a string of optionally negative ASCII digits * @param start Unix epoch for range start, in the same form and unit * @param end Unix epoch for range end, in the same form and unit * @param options optional: how the epochs are read and whether each end of the range is included * @returns boolean indicating whether value is between start and end * * @example isBetweenUnix(1705000000000, 1704000000000, 1706000000000) // true * @example isBetweenUnix(1705000000, 1704000000, 1706000000, { epochUnit: "seconds" }) // true * @example isBetweenUnix(1703000000000, 1704000000000, 1706000000000) // false * @example isBetweenUnix("1705000000", "1704000000", "1706000000", { epochUnit: "second" }) // true (digit strings) * @example isBetweenUnix(1705000000000, 1704000000000, 1706000000000, { timeZone: "Mars/Olympus" }) // false (unknown zone) */ export declare function isBetweenUnix(value: number | string, start: number | string, end: number | string, options?: { /** * The unit the epoch values are counted in: `"seconds"` or `"milliseconds"`, singular or * plural. Any other value returns `false`. * * @defaultValue `"milliseconds"` */ epochUnit?: UnixUnit; /** * A time zone that is validated only: the comparison is on exact instants, so the zone never * changes the result. It is an IANA name, a UTC offset (a time zone identifier such as * `+05:30`, `+0530` or `-08`, or a stored offset `±HH:MM[:SS]`, what `getTimeZoneOffset` * returns), or `"local"` for the system time zone. An unknown zone returns `false`. * * @defaultValue `"UTC"` */ timeZone?: string; /** * Whether `value` equal to `start` counts as inside the range. `false` requires it to be after * `start`. * * @defaultValue `true` */ inclusiveStart?: boolean; /** * Whether `value` equal to `end` counts as inside the range. `false` requires it to be before * `end`. * * @defaultValue `true` */ inclusiveEnd?: boolean; }): boolean;