areDatesEqualBy
Signature
Section titled “Signature”areDatesEqualBy(value1: string, value2: string, unit: Temporal.DateUnit, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): booleanimport { areDatesEqualBy } from "@northguild/gmt/plain/compare";Compare two ISO date strings for equality at a given calendar unit.
- Equality means both values share the same start-of-
unitboundary, so"month"requires the same month AND year — March 2023 and March 2024 are NOT equal by month, matching date-fns’sisSameMonthand Luxon’sdt.hasSame(other, "month"). This is a common point of confusion for callers expecting a bare “same month-of-year” comparison. "day"is equivalent toareDatesEqual."year","month","week"are computed viastartOfDate.- Returns false for an unsupported unit or invalid input. Mapping from date-fns (Decision 5,
context/roadmap/issues/J.md): isSameDay(a, b)→areDatesEqualBy(a, b, "day")isSameWeek(a, b, options)→areDatesEqualBy(a, b, "week", { weekStartsOn })isSameMonth(a, b)→areDatesEqualBy(a, b, "month")isSameYear(a, b)→areDatesEqualBy(a, b, "year")
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value1 |
string |
first ISO date string |
value2 |
string |
second ISO date string |
unit |
Temporal.DateUnit |
Temporal.DateUnit to compare by (“year” | “month” | “week” | “day”) |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
weekStartsOn? |
"monday" | "sunday" |
— |
Returns
Section titled “Returns”true if both dates share the same start-of-unit boundary, false on an unsupported unit or invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”areDatesEqualBy("2024-03-15", "2024-03-20", "month") // trueareDatesEqualBy("2023-03-15", "2024-03-15", "month") // false (same month, different year)areDatesEqualBy("2024-03-15", "2024-03-16", "day") // falseareDatesEqualBy("2024-03-15", "2024-03-15", "hour" as never) // false (unsupported unit)areDatesEqualBy("invalid", "2024-03-15", "month") // false