Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / date-fns-utc / getWeekNumber.ts
blobd4332632d77db8256b0011a847809944a876c33a
1 const MILLISECONDS_IN_WEEK = 604800000;
3 const getWeekNumber = (date: Date) => {
4     const start = new Date(date);
5     start.setUTCHours(0, 0, 0, 0);
7     const startOfYear = new Date(0);
8     startOfYear.setUTCFullYear(start.getUTCFullYear());
10     const diff = Math.max(start.getTime() - startOfYear.getTime(), 0);
11     const result = Math.round(diff / MILLISECONDS_IN_WEEK) + 1;
12     return result > 52 ? 1 : result;
15 export default getWeekNumber;