Skip to content

getLocaleDayOfWeek

getLocaleDayOfWeek(value: string, locale: string): number
import { getLocaleDayOfWeek } from "@northguild/gmt/plain/calculate";

Return the locale-relative day-of-week index for value.

  • 0 = the locale’s first day of week (e.g. Sunday for en-US, Monday for fr-FR).
  • Resolves the locale’s first day of week via Intl.Locale.prototype.weekInfo.
  • Falls back to Monday if the runtime’s weekInfo data doesn’t resolve a first day for the locale.
  • Returns null if value is not a valid ISO date or locale is unresolvable.
Parameter Type Description
value string ISO 8601 date string
locale string BCP 47 locale tag (e.g. “en-US”, “fr-FR”)

locale-relative day-of-week index (0–6) or null on invalid input

getLocaleDayOfWeek("2024-02-25", "en-US") // 0 (Sunday)
getLocaleDayOfWeek("2024-02-26", "en-US") // 1 (Monday)
getLocaleDayOfWeek("2024-02-26", "fr-FR") // 0 (Monday)
getLocaleDayOfWeek("invalid-date", "en-US") // null
getLocaleDayOfWeek("2024-02-29", "not-a-locale") // null

plain/calculate/getLocaleDayOfWeek.ts