export const getEndOfWeek = ( d ) => { const day = d . getDay ( ) ; return new Date ( d . getFullYear ( ) , d . getMonth ( ) , d . getDate ( ) + ( day === 0 ? day : 7 - day ) ) ; } ; export const getWeekNumber = ( d ) => { d = new Date ( Date . UTC ( d . getFullYear ( ) , d . getMonth ( ) , d . getDate ( ) ) ) ; d . setUTCDate ( d . getUTCDate ( ) + 4 - ( d . getUTCDay ( ) || 7 ) ) ; const yearStart = new Date ( Date . UTC ( d . getUTCFullYear ( ) , 0 , 1 ) ) ; const weekNo = Math . ceil ( ( ( ( d . valueOf ( ) - yearStart . valueOf ( ) ) / 86400000 ) + 1 ) / 7 ) ; return [ d . getUTCFullYear ( ) , weekNo ] ; } ; export const sameWeek = ( a , b ) => { const _a = getWeekNumber ( a ) ; const _b = getWeekNumber ( b ) ; return _a [ 0 ] === _b [ 0 ] && _a [ 1 ] === _b [ 1 ] ; } ; export const getStartOfDay = ( d ) => { return new Date ( d . getFullYear ( ) , d . getMonth ( ) , d . getDate ( ) ) ; } ; export const daysBetween = ( date1 , date2 ) => { const one_day = 1000 * 60 * 60 * 24 ; const date1_ms = getStartOfDay ( date1 ) . getTime ( ) ; const date2_ms = getStartOfDay ( date2 ) . getTime ( ) ; const difference_ms = date2_ms - date1_ms ; return Math . round ( difference_ms / one_day ) ; } ;