import { Constants } from './Constants' ; import { Day } from './Day' ; import { Locales } from './Locale' ; import { Op } from './Operation' ; import { Units } from './Units' ; /**
 * The calculated bounds of a DaySpan relative to a given day.
 */ export interface DaySpanBounds { /**
     * The top of the span within the rectangle of the given day.
     */ top : number ; /**
     * The bottom of the span within the rectangle of the givne day.
     */ bottom : number ; /**
     * The height of the span within the rectangle of the given day. This is
     * equivalent by `bottom - top`.
     */ height : number ; /**
     * The left of the span within the rectangle of the given day.
     */ left : number ; /**
     * The right of the span within the rectangle of the given day.
     */ right : number ; /**
     * The width of the span within the rectangle of the given day. This is
     * equivalent by `right - left`.
     */ width : number ; } /**
 * A class for a range of time between two [[Day]] timestamps.
 */ export class DaySpan { /**
     * The starting timestamp of the span (inclusive).
     */ public start : Day ; /**
     * The endind timestamp of the span (inclusive).
     */ public end : Day ; param start param end public constructor ( start , end ) { this . start = start ; this . end = end ; } /**
     * Whether this span starts and ends on the same timestamp.
     */ public get isPoint ( ) : boolean { return this . start . time === this . end . time ; } param day returns public contains ( day ) { return day . time >= this . start . time && day . time <= this . end . time ; } param day returns public compareTo ( day ) { return day . time < this . start . time ? - 1 : ( day . time > this . end . time ? 1 : 0 ) ; } param day see public matchesDay ( day ) { return this . contains ( day ) || day . sameDay ( this . start ) || day . sameDay ( this . end ) ; } param day see public matchesWeek ( day ) { return this . contains ( day ) || day . sameWeek ( this . start ) || day . sameWeek ( this . end ) ; } param day see public matchesMonth ( day ) { return this . contains ( day ) || day . sameMonth ( this . start ) || day . sameMonth ( this . end ) ; } param day see public matchesYear ( day ) { return this . contains ( day ) || day . sameYear ( this . start ) || day . sameYear ( this . end ) ; } param op param absolute returns see public millis ( op = Op . DOWN , absolute = true ) { return this . start . millisBetween ( this . end , op , absolute ) ; } param op param absolute returns see public seconds ( op = Op . DOWN , absolute = true ) { return this . start . secondsBetween ( this . end , op , absolute ) ; } param op param absolute returns see public minutes ( op = Op . DOWN , absolute = true ) { return this . start . minutesBetween ( this . end , op , absolute ) ; } param op param absolute returns see public hours ( op = Op . DOWN , absolute = true ) { return this . start . hoursBetween ( this . end , op , absolute ) ; } param op param absolute returns see public days ( op = Op . DOWN , absolute = true ) { return this . start . daysBetween ( this . end , op , absolute ) ; } param op param absolute returns see public weeks ( op = Op . DOWN , absolute = true ) { return this . start . weeksBetween ( this . end , op , absolute ) ; } param op param absolute returns see public months ( op = Op . DOWN , absolute = true ) { return this . start . monthsBetween ( this . end , op , absolute ) ; } param op param absolute returns see public years ( op = Op . DOWN , absolute = true ) { return this . start . yearsBetween ( this . end , op , absolute ) ; } param relativeTo return public startDelta ( relativeTo ) { return ( this . start . time - relativeTo . time ) / Constants . MILLIS_IN_DAY ; } param relativeTo return public endDelta ( relativeTo ) { return ( this . end . time - relativeTo . time ) / Constants . MILLIS_IN_DAY ; } param relativeTo param dayHeight param dayWidth param columnOffset param clip param offsetX param offsetY returns public getBounds ( relativeTo , dayHeight = 1 , dayWidth = 1 , columnOffset = 0 , clip = true , offsetX = 0 , offsetY = 0 ) { const startRaw = this . startDelta ( relativeTo ) ; const endRaw = this . endDelta ( relativeTo ) ; const start = clip ? Math . max ( 0 , startRaw ) : startRaw ; const end = clip ? Math . min ( 1 , endRaw ) : endRaw ; const left = columnOffset ; const right = dayWidth - left ; const top = start * dayHeight ; const bottom = end * dayHeight ; return { top : top + offsetY , bottom : bottom + offsetY , height : bottom - top , left : left + offsetX , right : right + offsetX , width : right } ; } param type param dayOfWeek param short param repeat param contextual param delimiter returns public summary ( type , dayOfWeek = true , short = false , repeat = false , contextual = true , delimiter = ' - ' ) { const formats = [ Locales . current . summaryDay , Locales . current . summaryWeek , Locales . current . summaryMonth , Locales . current . summaryYear ] ; const formatter = formats [ type ] ; const today = Day . today ( ) ; const showStartYear = ! contextual || ! this . start . sameYear ( today ) ; const showEndYear = ! contextual || ! this . end . sameYear ( today ) ; const start = this . start . format ( formatter ( short , dayOfWeek , showStartYear ) ) ; const end = this . end . format ( formatter ( short , dayOfWeek , showEndYear ) ) ; let summary = start ; if ( start !== end ) { if ( ! repeat ) { summary = this . start . format ( formatter ( short , dayOfWeek , ! this . start . sameYear ( this . end ) ) ) ; } summary += delimiter ; summary += end ; } else { summary = start ; } return summary ; } param span returns public intersects ( span ) { return ! ( this . end . time < span . start . time || this . start . time > span . end . time ) ; } param span returns public intersection ( span ) { const start = this . start . max ( span . start ) ; const end = this . end . min ( span . end ) ; return start . isAfter ( end ) ? null : new DaySpan ( start , end ) ; } param span returns public union ( span ) { const start = this . start . min ( span . start ) ; const end = this . end . max ( span . end ) ; return new DaySpan ( start , end ) ; } param day returns see public static point ( day ) { return new DaySpan ( day , day ) ; } }