@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
21 lines (20 loc) • 683 B
JavaScript
/**
* Resolve the set of ISO day-of-week numbers (1 = Monday .. 7 = Sunday)
* that count as "weekend" for a locale, via `Intl.Locale.prototype.weekInfo`.
*
* - Returns `null` if `locale` is not a valid BCP 47 tag.
* - Falls back to Saturday/Sunday (`[6, 7]`) if `weekInfo` is unavailable
* on the runtime (older engines) or unresolvable for the given locale.
*/
export function getLocaleWeekendDays(locale) {
try {
const weekInfo = new Intl.Locale(locale).weekInfo;
if (!weekInfo || !Array.isArray(weekInfo.weekend)) {
return new Set([6, 7]);
}
return new Set(weekInfo.weekend);
}
catch {
return null;
}
}