diff --git a/src/weekUtils.ts b/src/weekUtils.ts index d8ac22b..195ab40 100644 --- a/src/weekUtils.ts +++ b/src/weekUtils.ts @@ -5,11 +5,10 @@ export const getWeekNumber = (date: Date) => { export const getWeekOfYear = (): number => getWeekNumber(new Date()); -export const getWeekIsoNumber = (date: Date) => { - const onejan = new Date(date.getFullYear(), 0, 1); - const daysSinceOneJan = Math.floor((date.getTime() - onejan.getTime()) / 86400000); - const dayOfWeek = (onejan.getDay() + 6) % 7; - return Math.floor((daysSinceOneJan + dayOfWeek) / 7) + 1; +export const getWeekIsoNumber = (date: Date): number => { + const dayOfWeek = date.getDay(); + const thursday = new Date(date.getFullYear(), date.getMonth(), date.getDate() + (4 - dayOfWeek)); + return Math.ceil(((thursday.getTime() - new Date(thursday.getFullYear(), 0, 1).getTime()) / 86400000 + 1) / 7); }; export const getWeekIsoOfYear = (): number => getWeekIsoNumber(new Date());