isThisUnit
Signature
Section titled “Signature”isThisUnit(value: string, unit: SmallestUnit<DateUnit>, locale?: string | string[]): booleanReturn true when value falls in the same unit as today, per the system clock and system timeZone.
- Subsumes
isThisWeek/isThisMonth/isThisYear:unitis drawn from the sameTemporal.DateUnitareDatesEqualByuses. "day"is equivalent toisRelativeDay(value, 0).localeonly affects the"week"case — which day the week starts on varies by locale (e.g. fr-FR: Monday, pt-BR: Sunday). Whenunitis"week"andlocaleis given, the comparison usesgetLocaleStartOfWeekinstead of the ISO Monday-start defaultareDatesEqualByotherwise uses.- Compares against today, so this depends on the system clock and system timeZone. A caller needing determinism should use
isZonedThisUnitwith an explicit timeZone, or compare against an explicit reference withareDatesEqualBy. unitaccepts the singular or plural name ("month"or"months"), as Temporal does.localemay be a BCP 47 tag or a preference list of tags (ECMA-402); the first tag with locale data sets the week start.- Returns false for an unsupported unit or invalid input. The locale is validated for every unit, so an invalid locale returns false for
"day","month"and"year"too. - Compatibility: before 1.16.0 an invalid locale was ignored for every unit but
"week". Migrating from date-fns: isThisWeek(value)→isThisUnit(value, "week", "pt-BR"), or any locale whose week starts on Sunday: date-fns starts the week on Sunday (weekStartsOn: 0) by default, GMT on MondayisThisWeek(value, { weekStartsOn: 1 })→isThisUnit(value, "week")isThisMonth(value)→isThisUnit(value, "month")isThisYear(value)→isThisUnit(value, "year")
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainDate string |
unit | SmallestUnit<DateUnit> | date unit to compare by (“year” | “month” | “week” | “day”, or its plural) |
locale | string | string[] | optional BCP 47 locale tag or preference list — sets the “week” start (e.g. “fr-FR”, [“pt-BR”, “fr-FR”]) |
Returns
Section titled “Returns”true if value falls in the same unit as today, false on an unsupported unit or invalid input
Examples
Section titled “Examples”import { isThisUnit } from "@northguild/gmt/plain/compare";
isThisUnit("2024-03-15", "month") // true, if today is any day in March 2024Source
Section titled “Source”Accessibility
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.