UNPKG

@kamiazya/freebusy

Version:

Determine free blocks from a list of events.

45 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var DateTimeInput_1 = require("../utils/DateTimeInput"); /** * Block is a object for abstract handling * of the start and end of time. */ var Block = /** @class */ (function () { function Block(start, end) { this.start = DateTimeInput_1.convertDataTime(start); this.end = DateTimeInput_1.convertDataTime(end); if (this.start.isValid === false) { throw new Error('start value is invalid.'); } if (this.end.isValid === false) { throw new Error('end value is invalid.'); } if (this.start > this.end) { throw new Error('start is after then end.'); } } Block.prototype.clone = function () { return new Block(this.start, this.end); }; Block.prototype.subtract = function (other) { var notOverlapped = other.start > this.end || other.end < this.start; if (notOverlapped === true) { return [this.clone()]; } return [ new Block(this.start, other.start), new Block(other.end, this.end), ] .filter(function (b) { return b.end > b.start; }); }; Block.prototype.toISO8601 = function () { return { start: this.start.toISO(), end: this.end.toISO(), }; }; return Block; }()); exports.Block = Block; //# sourceMappingURL=Block.js.map