UNPKG

@jbouduin/holidays-lib

Version:
61 lines (60 loc) 2.71 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.RelativeToDateFactory = void 0; var errors_1 = require("../errors"); var holidays_1 = require("../holidays"); var types_1 = require("../types"); var base_factory_1 = require("./base-factory"); var RelativeToDateFactory = /** @class */ (function (_super) { __extends(RelativeToDateFactory, _super); //#endregion //#region Constructor & C° function RelativeToDateFactory() { return _super.call(this) || this; } //#endregion //#region Abstract methods implementation RelativeToDateFactory.prototype.createHoliday = function (key, category, cycle, validFrom, validTo) { return new holidays_1.RelativeHoliday(types_1.HolidayType.RELATIVE_TO_DATE, key, category, cycle, validFrom, validTo, this.relation, this.fix); }; RelativeToDateFactory.prototype.extractData = function (obj) { if (!obj.fix) { this.addError(errors_1.ErrorKey.RELATIVE_FIX_MISSING); } else if (!obj.fix.day && !obj.fix.month) { this.addError(errors_1.ErrorKey.RELATIVE_FIX_EMPTY); } else { this.fix = this.dataExtractor.extractFixedDate(obj.fix); } if (!obj.relation) { this.addError(errors_1.ErrorKey.RELATIVE_RELATION_MISSING); } else if (!obj.relation.which && !obj.relation.weekday && !obj.relation.when) { this.addError(errors_1.ErrorKey.RELATIVE_RELATION_EMPTY); } else { this.relation = this.dataExtractor.extractWhichWeekdayWhen(obj.relation); } }; RelativeToDateFactory.prototype.extractKey = function (obj) { return this.dataExtractor.extractStringKey(obj); }; return RelativeToDateFactory; }(base_factory_1.BaseFactory)); exports.RelativeToDateFactory = RelativeToDateFactory;