UNPKG

@studyportals/sp-hs-misc

Version:

Miscellaneous code used in HouseStark's projects

50 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeInterval = void 0; class TimeInterval { get startDate() { return this._startDate; } get endDate() { return this._endDate; } constructor(startDate, endDate) { if (endDate < startDate) { throw new Error("TimeInterval constructor was called with a endDate that is earlier than the beginDate"); } this._startDate = startDate; this._endDate = endDate; } static createFromTimeInterval(timeInterval) { return new TimeInterval(timeInterval.startDate, timeInterval.endDate); } /** * @deprecated Use TimeInterval.contains instead. */ isDateInInterval(date) { return this.contains(date); } contains(date) { return this.startDate <= date && date <= this.endDate; } toUTCDays() { const days = []; const millisecondsInADay = 24 * 60 * 60 * 1000; const lastDayUnixEpoch = Date.UTC(this.endDate.getUTCFullYear(), this.endDate.getUTCMonth(), this.endDate.getUTCDate()); const firstDayUnixEpoch = Date.UTC(this.startDate.getUTCFullYear(), this.startDate.getUTCMonth(), this.startDate.getUTCDate()); let currentDayUnixEpoch = firstDayUnixEpoch; while (currentDayUnixEpoch <= lastDayUnixEpoch) { days.push(new Date(currentDayUnixEpoch)); currentDayUnixEpoch += millisecondsInADay; } return days; } toJSON() { const obj = {}; obj.startDate = this.startDate; obj.endDate = this.endDate; return obj; } } exports.TimeInterval = TimeInterval; //# sourceMappingURL=time-interval.class.js.map