MCPcopy Index your code
hub / github.com/angular/angular / weekGetter

Function weekGetter

packages/common/src/i18n/format_date.ts:534–553  ·  view source on GitHub ↗
(size: number, monthBased = false)

Source from the content-addressed store, hash-verified

532}
533
534function 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.

Callers 1

getDateFormatterFunction · 0.85

Calls 4

getLocaleNumberSymbolFunction · 0.90
getThursdayThisIsoWeekFunction · 0.85
getFirstThursdayOfYearFunction · 0.85
padNumberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…