import { PositionCache , DateMarker , startOfDay , createDuration , asRoughMs , DateProfile , Duration , rangeContainsMarker , } from '@fullcalendar/common' ; export class TimeColsSlatsCoords { constructor ( public positions , private dateProfile , private slotDuration ) { } safeComputeTop ( date ) { let { dateProfile } = this ; if ( rangeContainsMarker ( dateProfile . currentRange , date ) ) { let startOfDayDate = startOfDay ( date ) ; let timeMs = date . valueOf ( ) - startOfDayDate . valueOf ( ) ; if ( timeMs >= asRoughMs ( dateProfile . slotMinTime ) && timeMs < asRoughMs ( dateProfile . slotMaxTime ) ) { return this . computeTimeTop ( createDuration ( timeMs ) ) ; } } return null ; } computeDateTop ( when , startOfDayDate ? ) { if ( ! startOfDayDate ) { startOfDayDate = startOfDay ( when ) ; } return this . computeTimeTop ( createDuration ( when . valueOf ( ) - startOfDayDate . valueOf ( ) ) ) ; } computeTimeTop ( duration ) { let { positions , dateProfile } = this ; let len = positions . els . length ; let slatCoverage = ( duration . milliseconds - asRoughMs ( dateProfile . slotMinTime ) ) / asRoughMs ( this . slotDuration ) ; let slatIndex ; let slatRemainder ; slatCoverage = Math . max ( 0 , slatCoverage ) ; slatCoverage = Math . min ( len , slatCoverage ) ; slatIndex = Math . floor ( slatCoverage ) ; slatIndex = Math . min ( slatIndex , len - 1 ) ; slatRemainder = slatCoverage - slatIndex ; return positions . tops [ slatIndex ] + positions . getHeight ( slatIndex ) * slatRemainder ; } }