import { createDuration , asRoughMs , formatIsoTimeString , addDurations , wholeDivideDurations , Duration , DateMarker , DateEnv , } from '@fullcalendar/common' ; export interface TimeSlatMeta { date : DateMarker ; time : Duration ; key : string ; isoTimeStr : string ; isLabeled : boolean ; } const STOCK_SUB_DURATIONS = [ { hours : 1 } , { minutes : 30 } , { minutes : 15 } , { seconds : 30 } , { seconds : 15 } , ] ; export function buildSlatMetas ( slotMinTime , slotMaxTime , explicitLabelInterval , slotDuration , dateEnv ) { let dayStart = new Date ( 0 ) ; let slatTime = slotMinTime ; let slatIterator = createDuration ( 0 ) ; let labelInterval = explicitLabelInterval || computeLabelInterval ( slotDuration ) ; let metas = [ ] ; while ( asRoughMs ( slatTime ) < asRoughMs ( slotMaxTime ) ) { let date = dateEnv . add ( dayStart , slatTime ) ; let isLabeled = wholeDivideDurations ( slatIterator , labelInterval ) !== null ; metas . push ( { date , time : slatTime , key : date . toISOString ( ) , isoTimeStr : formatIsoTimeString ( date ) , isLabeled , } ) ; slatTime = addDurations ( slatTime , slotDuration ) ; slatIterator = addDurations ( slatIterator , slotDuration ) ; } return metas ; } function computeLabelInterval ( slotDuration ) { let i ; let labelInterval ; let slotsPerLabel ; for ( i = STOCK_SUB_DURATIONS . length - 1 ; i >= 0 ; i -= 1 ) { labelInterval = createDuration ( STOCK_SUB_DURATIONS [ i ] ) ; slotsPerLabel = wholeDivideDurations ( labelInterval , slotDuration ) ; if ( slotsPerLabel !== null && slotsPerLabel > 1 ) { return labelInterval ; } } return slotDuration ; }