import { DateProfile } from '../DateProfileGenerator' ; import { diffWholeDays } from '../datelib/marker' ; import { createFormatter , FormatterInput } from '../datelib/formatting' ; import { DateRange } from '../datelib/date-range' ; import { DateEnv } from '../datelib/env' ; import { BaseOptions } from '../options' ; export function buildTitle ( dateProfile , viewOptions , dateEnv ) { let range ; if ( /^(year|month)$/ . test ( dateProfile . currentRangeUnit ) ) { range = dateProfile . currentRange ; } else { range = dateProfile . activeRange ; } return dateEnv . formatRange ( range . start , range . end , createFormatter ( viewOptions . titleFormat || buildTitleFormat ( dateProfile ) ) , { isEndExclusive : dateProfile . isRangeAllDay , defaultSeparator : viewOptions . titleRangeSeparator , } ) ; } function buildTitleFormat ( dateProfile ) { let { currentRangeUnit } = dateProfile ; if ( currentRangeUnit === 'year' ) { return { year : 'numeric' } ; } if ( currentRangeUnit === 'month' ) { return { year : 'numeric' , month : 'long' } ; } let days = diffWholeDays ( dateProfile . currentRange . start , dateProfile . currentRange . end ) ; if ( days !== null && days > 1 ) { return { year : 'numeric' , month : 'short' , day : 'numeric' } ; } return { year : 'numeric' , month : 'long' , day : 'numeric' } ; }