@akatek/timeslot
Version:
74 lines (70 loc) • 1.98 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
Timeslot: () => Timeslot
});
module.exports = __toCommonJS(src_exports);
// 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;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Timeslot
});