@eristack/business-calendar
Version:
Business days and holidays on YYYY-MM-DD wall dates — no timestamp import in core
74 lines (69 loc) • 2.59 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/zod/index.ts
var zod_exports = {};
__export(zod_exports, {
businessCalendarOptionsSchema: () => businessCalendarOptionsSchema,
wallDateSchema: () => wallDateSchema
});
module.exports = __toCommonJS(zod_exports);
// src/zod/schemas.ts
var import_zod = require("zod");
// src/core/errors.ts
var BusinessCalendarParseError = class extends Error {
code = "BUSINESS_CALENDAR_PARSE_ERROR";
constructor(message) {
super(message);
this.name = "BusinessCalendarParseError";
}
};
// src/core/wall-date.ts
var WALL_DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
function normalizeWallDate(value) {
const trimmed = value.trim();
const match = WALL_DATE_RE.exec(trimmed);
if (!match) {
throw new BusinessCalendarParseError(
`Invalid wall date "${value}" \u2014 expected YYYY-MM-DD`
);
}
const year = Number(match[1]);
const month = Number(match[2]);
const day = Number(match[3]);
const utc = Date.UTC(year, month - 1, day);
const check = new Date(utc);
if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day) {
throw new BusinessCalendarParseError(`Invalid calendar date "${value}"`);
}
const mm = String(month).padStart(2, "0");
const dd = String(day).padStart(2, "0");
return `${year}-${mm}-${dd}`;
}
// src/zod/schemas.ts
var wallDateSchema = import_zod.z.string().transform((value) => normalizeWallDate(value));
var businessCalendarOptionsSchema = import_zod.z.object({
weekendDays: import_zod.z.array(import_zod.z.number().int().min(0).max(6)),
holidays: import_zod.z.array(import_zod.z.string())
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
businessCalendarOptionsSchema,
wallDateSchema
});
//# sourceMappingURL=index.cjs.map