areDateTimesEqualBy
Signature
Section titled “Signature”areDateTimesEqualBy(value1: string, value2: string, unit: any, optionsArg?: { weekStartsOn?: "monday" | "sunday"; fractionalSecondDigits?: FractionalDigit; }): booleanimport { areDateTimesEqualBy } from "@northguild/gmt/plain/compare";Compare two ISO datetime strings for equality at a given 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"). - Supports the full
Temporal.DateUnit \| Temporal.TimeUnitrange, down to"nanosecond". - Returns false for an unsupported unit or invalid input. Mapping from date-fns (Decision 5,
context/roadmap/issues/J.md): isSameDay(a, b)→areDateTimesEqualBy(a, b, "day")isSameHour(a, b)→areDateTimesEqualBy(a, b, "hour")isSameMinute(a, b)→areDateTimesEqualBy(a, b, "minute")isSameSecond(a, b)→areDateTimesEqualBy(a, b, "second")isSameMonth(a, b)→areDateTimesEqualBy(a, b, "month")isSameYear(a, b)→areDateTimesEqualBy(a, b, "year")
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value1 |
string |
first ISO datetime string |
value2 |
string |
second ISO datetime string |
unit |
any |
Temporal.DateUnit | Temporal.TimeUnit to compare by |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
weekStartsOn? |
"monday" | "sunday" |
— |
fractionalSecondDigits? |
FractionalDigit |
— |
Returns
Section titled “Returns”true if both datetimes 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”areDateTimesEqualBy("2024-03-15T10:00:00", "2024-03-15T18:00:00", "day") // trueareDateTimesEqualBy("2024-03-15T10:30:00", "2024-03-15T10:45:00", "hour") // trueareDateTimesEqualBy("2024-03-15T10:30:00", "2024-03-15T11:00:00", "hour") // falseareDateTimesEqualBy("2023-03-15T10:00:00", "2024-03-15T10:00:00", "month") // false (same month, different year)areDateTimesEqualBy("invalid", "2024-03-15T10:00:00", "day") // false