-
Notifications
You must be signed in to change notification settings - Fork 198
Open
Description
I'm trying to create open-ended ranges in a TypeScript class, but moment.range() seems to only accept Dates or Moments as inputs, not null or undefined.
import * as Moment from 'moment'
import { extendMoment, MomentRange, DateRange } from 'moment-range'
import {isNullOrUndefined} from "util";
const moment = extendMoment(Moment) as unknown as typeof Moment & MomentRange;
export class Time {
constructor(
public startDate: Moment.Moment | undefined,
public endDate: Moment.Moment | undefined
) {}
overlapsWith(otherTime: Time): DateRange | undefined {
if((this.startDate === undefined && this.endDate === undefined)
|| (otherTime.startDate === undefined && otherTime.endDate === undefined)) {
return undefined;
}
const thisRange = moment.range(this.startDate, this.endDate);
const otherRange = moment.range(otherTime.startDate, otherTime.endDate);
const intersection = thisRange.intersect(otherRange);
if(intersection === null) {
return undefined;
} else {
return intersection;
}
}
}Those 2 lines fail:
const thisRange = moment.range(this.startDate, this.endDate);
const otherRange = moment.range(otherTime.startDate, otherTime.endDate);michaeldawson, charstarstars, trevorr and msarakon
Metadata
Metadata
Assignees
Labels
No labels