@nesto-software/moment-holiday-sweden
Version:
The swedish locale for moment-holiday.
47 lines • 2.29 kB
JavaScript
;
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var moment = require("moment");
var moment_holiday_core_1 = require("@nesto-software/moment-holiday-core");
var AllHallowsDependentDate = /** @class */ (function (_super) {
__extends(AllHallowsDependentDate, _super);
/**
* Create a new all hallows day dependent date.
* @param offset number of days before or after all hallows day - positive number means after, negative number before all hallows day
*/
function AllHallowsDependentDate(offset) {
var _this = _super.call(this) || this;
_this.offset = offset;
return _this;
}
AllHallowsDependentDate.prototype.resolve = function (year) {
// Alla helgons dag occurs on the saturday that exists during the period 31 oct - 6 nov
var oct31 = moment({ year: year, month: 9, day: 31 });
var allHallowsDayMoment = oct31;
if (oct31.isoWeekday() == 7) {
// October 31 is a sunday, Alla helgons dag can only be on the 6th of nov
allHallowsDayMoment = moment({ year: year, month: 10, day: 6 });
}
else if (oct31.isoWeekday() < 6) { // Oct 31 is monday-friday, calculate how many days until saturday
var day = 6 - oct31.isoWeekday();
allHallowsDayMoment = moment({ year: year, month: 10, day: day });
}
allHallowsDayMoment.add(this.offset, "days"); // the moment setter has side effects
return allHallowsDayMoment;
};
return AllHallowsDependentDate;
}(moment_holiday_core_1.AbstractDate));
exports.AllHallowsDependentDate = AllHallowsDependentDate;
//# sourceMappingURL=all-hallows-dependent-date.js.map