// (C) 2007-2019 GoodData Corporation import { datesBetween } from "../datesBetween/datesBetween"; export class DateRange { public static DEFAULT_FROM: string = "01-01-2015"; public static fromDates(from: Date, to: Date) { const date = new DateRange(); date.from = from; date.to = to; return date; } private from: Date; private to: Date; constructor(from?: string, to?: string) { this.from = new Date(from ? from : DateRange.DEFAULT_FROM); this.to = to ? new Date(to) : new Date(); } public getFromDate(): Date { return this.from; } public getToDate(): Date { return this.to; } public getDatesBetween(): IterableIterator { return datesBetween(this.getFromDate(), this.getToDate()); } public intersect(other: DateRange): DateRange { // Maximum of left boundaries const fromDate = new Date(Math.max(other.getFromDate().getTime(), this.getFromDate().getTime())); // Minimum of right boundaries const toDate = new Date(Math.min(other.getToDate().getTime(), this.getToDate().getTime())); return DateRange.fromDates(fromDate, toDate); } }