UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

26 lines (24 loc) • 929 B
import { localeWeekInfo } from "./localeWeekInfo.js"; // src/internal/getLocaleFirstDayOfWeek.ts /** * Resolve the ISO day-of-week number (1 = Monday .. 7 = Sunday) that a * locale considers the first day of the week, from its CLDR week data * (`Intl.Locale#getWeekInfo`, or the older `weekInfo` accessor — see * `localeWeekInfo`). * * - Returns `null` if `locale` is not a well-formed BCP 47 tag; a well-formed tag with no * locale data does not throw, so it does not return `null` either. * - Falls back to `1` (Monday, matching GMT's existing ISO default in * `startOfDate`/`startOfZoned`) if the runtime exposes no week data or * none for the given locale. */ function getLocaleFirstDayOfWeek(locale) { try { const weekInfo = localeWeekInfo(locale); if (!weekInfo || typeof weekInfo.firstDay !== "number") return 1; return weekInfo.firstDay; } catch { return null; } } export { getLocaleFirstDayOfWeek };