import { HOUR } from 'common/enums' ; export const timeout = ( ms , promise ) => { return new Promise ( ( resolve , reject ) => { setTimeout ( ( ) => { reject ( new Error ( 'timeout' ) ) ; } , ms ) ; promise . then ( resolve , reject ) ; } ) ; } ; export const getPunishExpiredDate = ( days , _date ? ) => { const date = new Date ( ( _date ?. getTime ( ) || Date . now ( ) ) + 8 * HOUR ) ; date . setUTCHours ( 0 , 0 , 0 , 0 ) ; const offset = days > 0 ? 1 + days : 0 ; date . setDate ( date . getDate ( ) + offset ) ; date . setHours ( date . getHours ( ) - 8 ) ; return date ; } ; export const getUTC8Midnight = ( _date ? ) => { const date = new Date ( ( _date ?. getTime ( ) || Date . now ( ) ) + 8 * HOUR ) ; date . setUTCHours ( 0 , 0 , 0 , 0 ) ; date . setHours ( date . getHours ( ) - 8 ) ; return date ; } ; export const getUTCNextMonthDayOne = ( _date ? ) => { const date = new Date ( ( _date ?. getTime ( ) || Date . now ( ) ) + 8 * HOUR ) ; date . setUTCHours ( 0 , 0 , 0 , 0 ) ; const month = date . getMonth ( ) ; const isLastMonthOfYear = month === 11 ; date . setDate ( 1 ) ; if ( isLastMonthOfYear ) { date . setMonth ( 0 ) ; } else { date . setMonth ( month + 1 ) ; } if ( isLastMonthOfYear ) { date . setFullYear ( date . getFullYear ( ) + 1 ) ; } return date . getTime ( ) ; } ; export const getUTCNextMonday = ( _date ? ) => { const date = new Date ( ( _date ?. getTime ( ) || Date . now ( ) ) + 8 * HOUR ) ; date . setUTCHours ( 0 , 0 , 0 , 0 ) ; const offset = ( ( 7 - date . getDay ( ) ) % 7 ) + 1 ; date . setDate ( date . getDate ( ) + offset ) ; return date . getTime ( ) ; } ;