(locale: string)
| 290 | } |
| 291 | |
| 292 | function 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 | weekInfo = localeInst.getWeekInfo(); |
| 302 | if (weekInfo) { |
| 303 | cachedWeekInfo.set(locale, weekInfo); |
| 304 | return weekInfo.firstDay; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | let region = getRegion(locale); |
| 309 | if (locale.includes('-fw-')) { |
| 310 | // 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 |
| 311 | // where the fw attribute could be followed by another unicode locale extension or not |
| 312 | let day = locale.split('-fw-')[1].split('-')[0]; |
| 313 | if (day === 'mon') { |
| 314 | weekInfo = {firstDay: 1}; |
| 315 | } else if (day === 'tue') { |
| 316 | weekInfo = {firstDay: 2}; |
| 317 | } else if (day === 'wed') { |
| 318 | weekInfo = {firstDay: 3}; |
| 319 | } else if (day === 'thu') { |
| 320 | weekInfo = {firstDay: 4}; |
| 321 | } else if (day === 'fri') { |
| 322 | weekInfo = {firstDay: 5}; |
| 323 | } else if (day === 'sat') { |
| 324 | weekInfo = {firstDay: 6}; |
| 325 | } else { |
| 326 | weekInfo = {firstDay: 0}; |
| 327 | } |
| 328 | } else if (locale.includes('-ca-iso8601')) { |
| 329 | weekInfo = {firstDay: 1}; |
| 330 | } else { |
| 331 | weekInfo = {firstDay: region ? weekStartData[region] || 0 : 0}; |
| 332 | } |
| 333 | cachedWeekInfo.set(locale, weekInfo); |
| 334 | } |
| 335 | |
| 336 | return weekInfo.firstDay; |
| 337 | } |
| 338 | |
| 339 | /** Returns the number of weeks in the given month and locale. */ |
| 340 | export function getWeeksInMonth( |
no test coverage detected