MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getWeekStart

Function getWeekStart

packages/@internationalized/date/src/queries.ts:292–338  ·  view source on GitHub ↗
(locale: string)

Source from the content-addressed store, hash-verified

290}
291
292function getWeekStart(locale: string): number {
293 // TODO: use Intl.Locale for this once browsers support the weekInfo property
294 // https://github.com/tc39/proposal-intl-locale-info
295 let weekInfo = cachedWeekInfo.get(locale);
296 if (!weekInfo) {
297 if (Intl.Locale) {
298 // @ts-ignore
299 let localeInst = new Intl.Locale(locale);
300 if ('getWeekInfo' in localeInst) {
301 // @ts-expect-error
302 weekInfo = localeInst.getWeekInfo();
303 if (weekInfo) {
304 cachedWeekInfo.set(locale, weekInfo);
305 return weekInfo.firstDay;
306 }
307 }
308 }
309 let region = getRegion(locale);
310 if (locale.includes('-fw-')) {
311 // pull the value for the attribute fw from strings such as en-US-u-ca-iso8601-fw-tue or en-US-u-ca-iso8601-fw-mon-nu-thai
312 // where the fw attribute could be followed by another unicode locale extension or not
313 let day = locale.split('-fw-')[1].split('-')[0];
314 if (day === 'mon') {
315 weekInfo = {firstDay: 1};
316 } else if (day === 'tue') {
317 weekInfo = {firstDay: 2};
318 } else if (day === 'wed') {
319 weekInfo = {firstDay: 3};
320 } else if (day === 'thu') {
321 weekInfo = {firstDay: 4};
322 } else if (day === 'fri') {
323 weekInfo = {firstDay: 5};
324 } else if (day === 'sat') {
325 weekInfo = {firstDay: 6};
326 } else {
327 weekInfo = {firstDay: 0};
328 }
329 } else if (locale.includes('-ca-iso8601')) {
330 weekInfo = {firstDay: 1};
331 } else {
332 weekInfo = {firstDay: region ? weekStartData[region] || 0 : 0};
333 }
334 cachedWeekInfo.set(locale, weekInfo);
335 }
336
337 return weekInfo.firstDay;
338}
339
340/** Returns the number of weeks in the given month and locale. */
341export function getWeeksInMonth(

Callers 1

getDayOfWeekFunction · 0.85

Calls 2

getRegionFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected