import { utcToZonedTime , zonedTimeToUtc } from "date-fns-tz" ; import { Timezone } from "./timzones" ; const OPENING_HOURS = 8 ; const CLOSING_HOURS = 14 ; const MS_PER_CYCLE = 1000 * 3600 * ( OPENING_HOURS + CLOSING_HOURS ) ; const MS_PER_OPEN = 1000 * 3600 * OPENING_HOURS ; export function isPlatformOpenedAt ( date , timezone ) { const reference = utcToZonedTime ( new Date ( process . env . NEXT_PUBLIC_REFERENCE_OPENING ! ) , timezone . utc [ 0 ] ) ; const diff = ( date . getTime ( ) - reference . getTime ( ) ) / 1000 ; const hours = diff / 3600 ; const cycleHours = hours % ( OPENING_HOURS + CLOSING_HOURS ) ; return cycleHours < OPENING_HOURS ; } returns export function getMsUntilClose ( ) { const reference = new Date ( process . env . NEXT_PUBLIC_REFERENCE_OPENING ! ) ; const diff = Date . now ( ) - reference . getTime ( ) ; const cycleTime = diff % MS_PER_CYCLE ; return MS_PER_OPEN - cycleTime ; } returns export function getNextCycleStartTime ( ) { const reference = new Date ( process . env . NEXT_PUBLIC_REFERENCE_OPENING ! ) ; const currentTime = Date . now ( ) ; const diff = currentTime - reference . getTime ( ) ; const cycleTime = diff % MS_PER_CYCLE ; const startCurrentCycle = currentTime - cycleTime ; return startCurrentCycle + MS_PER_CYCLE ; }