import { DateMarker , startOfDay , addDays , diffDays , diffDayAndTime } from '../datelib/marker' ; import { Duration , asRoughMs , createDuration } from '../datelib/duration' ; import { DateEnv } from '../datelib/env' ; import { DateRange , OpenDateRange } from '../datelib/date-range' ; export function computeAlignedDayRange ( timedRange ) { let dayCnt = Math . floor ( diffDays ( timedRange . start , timedRange . end ) ) || 1 ; let start = startOfDay ( timedRange . start ) ; let end = addDays ( start , dayCnt ) ; return { start , end } ; } export function computeVisibleDayRange ( timedRange , nextDayThreshold = createDuration ( 0 ) ) { let startDay = null ; let endDay = null ; if ( timedRange . end ) { endDay = startOfDay ( timedRange . end ) ; let endTimeMS = timedRange . end . valueOf ( ) - endDay . valueOf ( ) ; if ( endTimeMS && endTimeMS >= asRoughMs ( nextDayThreshold ) ) { endDay = addDays ( endDay , 1 ) ; } } if ( timedRange . start ) { startDay = startOfDay ( timedRange . start ) ; if ( endDay && endDay <= startDay ) { endDay = addDays ( startDay , 1 ) ; } } return { start : startDay , end : endDay } ; } export function isMultiDayRange ( range ) { let visibleRange = computeVisibleDayRange ( range ) ; return diffDays ( visibleRange . start , visibleRange . end ) > 1 ; } export function diffDates ( date0 , date1 , dateEnv , largeUnit ? ) { if ( largeUnit === 'year' ) { return createDuration ( dateEnv . diffWholeYears ( date0 , date1 ) , 'year' ) ! ; } if ( largeUnit === 'month' ) { return createDuration ( dateEnv . diffWholeMonths ( date0 , date1 ) , 'month' ) ! ; } return diffDayAndTime ( date0 , date1 ) ; }