UNPKG

@akatek/timeslot

Version:

47 lines (45 loc) 967 B
// src/utils.ts var isValid = (date) => date instanceof Date && !isNaN(date.valueOf()); // src/Timeslot.ts var Timeslot = class { constructor(start, end) { if (!isValid(start)) { throw new Error("Invalid start date"); } if (!isValid(end)) { throw new Error("Invalid end date"); } if (end < start) { throw new Error("Start must be before end"); } this.start = start; this.end = end; } isEqual(slot) { return this.start === slot.start && this.end === slot.end; } isBefore(slot) { return this.start < slot.start && this.end < slot.end; } isAfter(slot) { return this.start > slot.start && this.end > slot.end; } isOverlaps(slot) { return this.start <= slot.end && this.end >= slot.start; } getStart() { return this.start; } getEnd() { return this.end; } setStart(start) { this.start = start; } setEnd(end) { this.end = end; } }; export { Timeslot };