Skip to content

areUnixEqualBy

areUnixEqualBy(value1: number, value2: number, unit: DateTimeUnit, options?: { epochUnit?: UnixUnit; timeZone?: string; weekStartsOn?: "monday" | "sunday"; }): boolean
import { areUnixEqualBy } from "@northguild/gmt/unix/compare";

Compare two Unix epoch values for equality at a given unit.

  • Both values are resolved to the start of unit in options.timeZone (default: the system time zone) before comparison, so "day" compares calendar days in that zone, not raw epoch buckets.
  • "month" requires the same month AND year, matching areDateTimesEqualBy.
  • Returns false for an unsupported unit or invalid input. Mapping from date-fns (Decision 5, context/roadmap/issues/J.md):
  • isSameDay(a, b)areUnixEqualBy(a, b, "day")
  • isSameMonth(a, b)areUnixEqualBy(a, b, "month")
  • isSameYear(a, b)areUnixEqualBy(a, b, "year")
Parameter Type Description
value1 number first Unix epoch value
value2 number second Unix epoch value
unit DateTimeUnit Temporal.DateUnit | Temporal.TimeUnit to compare by

options

Option Type Default
epochUnit? UnixUnit
timeZone? string
weekStartsOn? "monday" | "sunday"

true if both values share the same start-of-unit boundary, false on an unsupported unit or invalid input

areUnixEqualBy(1710498000000, 1710503000000, "day", { timeZone: "UTC" }) // true (both fall on 2024-03-15 in UTC)
areUnixEqualBy(1704067200000, 1735689600000, "year", { timeZone: "UTC" }) // false (2024-01-01 vs 2025-01-01)
areUnixEqualBy(Number.NaN, 1710498000000, "day") // false

unix/compare/areUnixEqualBy.ts