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;