getLocaleStartOfWeek
Signature
Section titled “Signature”getLocaleStartOfWeek(value: string, locale: string): stringimport { getLocaleStartOfWeek } from "@northguild/gmt/plain/calculate";Return the start of the week containing value, using locale’s
- first day of week (e.g. en-US: Sunday, fr-FR: Monday).
- Resolves the locale’s first day of week via
Intl.Locale.prototype.weekInfo. - Falls back to Monday if the runtime’s
weekInfodata doesn’t resolve a first day for the locale. - Distinct from
startOfDate(value, "week", { weekStartsOn }), which takes an explicit ISO-biasedweekStartsOnoption instead of deriving it from a locale. - Returns “” if
valueorlocaleis invalid.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO 8601 date string |
locale |
string |
BCP 47 locale tag (e.g. “en-US”, “fr-FR”) |
Returns
Section titled “Returns”ISO 8601 date string for the start of value’s locale-relative week, or “” on invalid input
Examples
Section titled “Examples”getLocaleStartOfWeek("2024-02-29", "en-US") // "2024-02-25" (Sunday)getLocaleStartOfWeek("2024-02-29", "fr-FR") // "2024-02-26" (Monday)getLocaleStartOfWeek("invalid-date", "en-US") // ""getLocaleStartOfWeek("2024-02-29", "not-a-locale") // ""