From ca571736abb2d3c57048af58e61067cc6421be8e Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Thu, 20 Feb 2025 19:44:52 +1100 Subject: [PATCH] fix: correct week number calculation logic in calculateWeekNum utility --- src/utils/calculateWeekNum.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/calculateWeekNum.ts b/src/utils/calculateWeekNum.ts index b7ebbc7..35e5428 100644 --- a/src/utils/calculateWeekNum.ts +++ b/src/utils/calculateWeekNum.ts @@ -2,12 +2,13 @@ export default (date: Date): { weekYear: number, weekNum: number } => { const tempDate = new Date(date) tempDate.setHours(0, 0, 0, 0) - tempDate.setDate(tempDate.getDate() + 3 - (tempDate.getDay() || 7)) + tempDate.setDate(tempDate.getDate() + 4 - (tempDate.getDay() || 7)) - const firstFriday = new Date(tempDate.getFullYear(), 0, 5) // Changed to 5 for Friday - firstFriday.setDate(firstFriday.getDate() + 3 - (firstFriday.getDay() || 7)) + const forthDay = new Date(tempDate.getFullYear(), 0, 4) + console.log(forthDay) + forthDay.setDate(forthDay.getDate() + 4 - (forthDay.getDay() || 7)) - const diffInDays = Math.floor((tempDate.getTime() - firstFriday.getTime()) / (24 * 60 * 60 * 1000)) + const diffInDays = Math.floor((tempDate.getTime() - forthDay.getTime()) / (24 * 60 * 60 * 1000)) const weekNum = Math.ceil((diffInDays + 1) / 7)