Skip to content

areZonedEqualBy

areZonedEqualBy(value1: string, value2: string, unit: DateTimeUnit, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): boolean
import { areZonedEqualBy } from "@northguild/gmt/zoned/compare";

Compare two zoned ISO datetime strings for equality at a given unit.

  • Equality is measured on each value’s own local wall-clock fields (its own time zone), not on the underlying instant or time zone identifier — the same instant can be “the same day” in one zone and a different day in another, and this function answers per each value’s own zone, the way Luxon’s dt.hasSame(other, unit) does for zoned DateTimes.
  • "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)areZonedEqualBy(a, b, "day")
  • isSameMonth(a, b)areZonedEqualBy(a, b, "month")
  • isSameYear(a, b)areZonedEqualBy(a, b, "year")
Parameter Type Description
value1 string first zoned ISO datetime string
value2 string second zoned ISO datetime string
unit DateTimeUnit Temporal.DateUnit | Temporal.TimeUnit to compare by

options

Option Type Default
weekStartsOn? "monday" | "sunday"

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

areZonedEqualBy("2024-03-15T10:00:00-04:00[America/New_York]", "2024-03-15T20:00:00+01:00[Europe/Berlin]", "day") // true (both are local March 15 in their own zone)
areZonedEqualBy("2024-03-15T23:30:00-04:00[America/New_York]", "2024-03-16T04:30:00+00:00[UTC]", "day") // false (same instant, different local calendar day per zone)
areZonedEqualBy("invalid", "2024-03-15T10:00:00-04:00[America/New_York]", "day") // false

zoned/compare/areZonedEqualBy.ts