(size: number, monthBased = false)
| 532 | } |
| 533 | |
| 534 | function weekGetter(size: number, monthBased = false): DateFormatter { |
| 535 | return function (date: Date, locale: string) { |
| 536 | let result; |
| 537 | if (monthBased) { |
| 538 | const nbDaysBefore1stDayOfMonth = |
| 539 | new Date(date.getFullYear(), date.getMonth(), 1).getDay() - 1; |
| 540 | const today = date.getDate(); |
| 541 | result = 1 + Math.floor((today + nbDaysBefore1stDayOfMonth) / 7); |
| 542 | } else { |
| 543 | const thisThurs = getThursdayThisIsoWeek(date); |
| 544 | // Some days of a year are part of next year according to ISO 8601. |
| 545 | // Compute the firstThurs from the year of this week's Thursday |
| 546 | const firstThurs = getFirstThursdayOfYear(thisThurs.getFullYear()); |
| 547 | const diff = thisThurs.getTime() - firstThurs.getTime(); |
| 548 | result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week |
| 549 | } |
| 550 | |
| 551 | return padNumber(result, size, getLocaleNumberSymbol(locale, NumberSymbol.MinusSign)); |
| 552 | }; |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Returns a date formatter that provides the week-numbering year for the input date. |
no test coverage detected
searching dependent graphs…