UNPKG

@kamiazya/freebusy

Version:

Determine free blocks from a list of events.

34 lines 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Block_1 = require("./Block"); var ScopeTime_1 = require("./ScopeTime"); var utils_1 = require("../utils"); var BlockArray = /** @class */ (function () { function BlockArray(blocks) { this.blocks = blocks; } BlockArray.days = function (startDate, endDate, scope) { if (scope === void 0) { scope = new ScopeTime_1.ScopeTime(); } var s = utils_1.convertDataTime(startDate); var e = utils_1.convertDataTime(endDate); var cur = s; var blocks = []; while (cur < e) { var day = (cur.day + 6) % 7; // rotate number to use Sun as beginning of week var start = cur.plus({ hours: scope.start(day) }); var end = cur.plus({ hours: scope.end(day) }); blocks.push(new Block_1.Block(start, end)); cur = cur.plus({ days: 1 }); } return new BlockArray(blocks); }; BlockArray.prototype.subtract = function (subtrahend) { return new BlockArray(Array.prototype.concat.apply([], this.blocks.map(function (block) { return block.subtract(subtrahend); }))); }; BlockArray.prototype.toISO8601 = function () { return this.blocks.map(function (block) { return block.toISO8601(); }); }; return BlockArray; }()); exports.BlockArray = BlockArray; //# sourceMappingURL=BlockArray.js.map