Skip to content

Commit

Permalink
MIM-2168: Fixed bug where weeknr is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
ssb-cgn committed Jan 21, 2025
1 parent a19f87e commit eace5dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/main/resources/lib/ssb/utils/variantUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { groupBy } from '/lib/vendor/ramda'

import { getMainSubject, getMainSubjectStatistic } from '/lib/ssb/utils/parentUtils'
import { sameDay, createMonthName, formatDate, isSameOrBefore } from '/lib/ssb/utils/dateUtils'
import { parseISO, getMonth, getYear, getDate } from '/lib/vendor/dateFns'
import { parseISO, getMonth, getYear, getDate, getISOWeek } from '/lib/vendor/dateFns'
import * as util from '/lib/util'
import {
type DayReleases,
Expand Down Expand Up @@ -186,20 +186,12 @@ function calculateMonth(previousFrom: string, language: string): string {
})
}

function getWeek(date: Date): number {
const onejan: number = new Date(date.getFullYear(), 0, 1).getTime()
const today: number = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()
const diff: number = today - onejan
const dayOfYear: number = (diff + 86400000) / 86400000
return Math.ceil(dayOfYear / 7)
}

function calculateWeek(previousFrom: string, language: string): string {
const date: Date = new Date(previousFrom)
return localize({
key: 'period.week',
locale: language,
values: [getWeek(date).toString(), date.getFullYear().toString()],
values: [getISOWeek(date).toString(), date.getFullYear().toString()],
})
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lib/vendor/dateFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export { isBefore } from 'date-fns/isBefore'
export { isSameDay } from 'date-fns/isSameDay'
export { isSameSecond } from 'date-fns/isSameSecond'
export { formatDistanceToNowStrict } from 'date-fns/formatDistanceToNowStrict'
export { getISOWeek } from 'date-fns/getISOWeek'

0 comments on commit eace5dc

Please sign in to comment.