fix: correct week number calculation logic in calculateWeekNum utility
All checks were successful
Publish to npm / publish (push) Successful in 29s

This commit is contained in:
Astrian Zheng 2025-02-20 19:44:52 +11:00
parent 39ffb6f784
commit ca571736ab
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA

View File

@ -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)