Skip to content

isBetweenUnix

isBetweenUnix(value: string | number, start: string | number, end: string | number, options?: { epochUnit?: UnixUnit; timeZone?: string; inclusiveStart?: boolean; inclusiveEnd?: boolean; }): boolean

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.
ParameterTypeDescription
valuestring | numberUnix epoch to check: a safe integer, or a string of optionally negative ASCII digits
startstring | numberUnix epoch for range start, in the same form and unit
endstring | numberUnix epoch for range end, in the same form and unit

options

optional: how the epochs are read and whether each end of the range is included

OptionTypeDefaultDescription
epochUnit?"seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit)"milliseconds"The unit the epoch values are counted in: "seconds" or "milliseconds", singular or plural. Any other value returns false.
timeZone?string"UTC"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.
inclusiveStart?booleantrueWhether value equal to start counts as inside the range. false requires it to be after start.
inclusiveEnd?booleantrueWhether value equal to end counts as inside the range. false requires it to be before end.

boolean indicating whether value is between start and end

import { isBetweenUnix } from "@northguild/gmt/unix/calculate";
isBetweenUnix(1705000000000, 1704000000000, 1706000000000) // true
output 

unix/calculate/isBetweenUnix.ts