Skip to content

Commit

Permalink
fix(period-week-number): not using the current week startdate when fo…
Browse files Browse the repository at this point in the history
…rce week set to true
  • Loading branch information
Mohammad Taha committed Apr 9, 2024
1 parent d67b08e commit 522936f
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class WeekNumberPipe implements PipeTransform {
firstWeekFirstDate = subDays(firstWeekFirstDate, customDateDay);
} else {
firstWeekFirstDate = addWeeks(firstWeekFirstDate, firstWeekMonth.week);
firstWeekFirstDate.setHours(12, 0, 0, 0);
}
firstWeekFirstDate.setHours(12, 0, 0, 0);
dateDay = this.getDayInView(dateClone, weekStartsOn);
currentWeekStartDate = subDays(dateClone, dateDay);

Expand Down Expand Up @@ -109,9 +109,11 @@ export class WeekNumberPipe implements PipeTransform {
}

if (ycConfig.periodWeekNumber) {
date.setHours(12, 0, 0, 0);
// if forceWeek then use currentWeekStartDate instead of provided date
const currentYearStartDiff =
(date.getTime() - firstWeekFirstDate.getTime()) / millisecondsInADay;
((forceWeek ? currentWeekStartDate : dateClone).getTime() -
firstWeekFirstDate.getTime()) /
millisecondsInADay;

// calculating period week number from range [1-4] using the week number calculated above
let week = result === 53 ? 1 : result;
Expand All @@ -125,7 +127,8 @@ export class WeekNumberPipe implements PipeTransform {
const weekNumber = week % 4 || 4;

const nextYearStartDiff =
(nextYearFirstDate.getTime() - date.getTime()) / millisecondsInADay;
(nextYearFirstDate.getTime() - dateClone.getTime()) /
millisecondsInADay;

// calculation for the "Adjustment Week" if days remaining are in multiple of 7
if (nextYearStartDiff % 7 === 0 && nextYearStartDiff <= 35) {
Expand Down

0 comments on commit 522936f

Please sign in to comment.