UNPKG

seasonal-overrides

Version:

A typescript framework for applying custom behavior to a website client-side based on the season or day of the year.

48 lines 2.17 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 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 override_1 = require("./override"); var SeasonalOverride = (function (_super) { __extends(SeasonalOverride, _super); function SeasonalOverride(beginMonth, beginDay, endDay, endMonth) { var _this = _super.call(this) || this; _this.beginMonth = beginMonth; _this.beginDay = beginDay; if (typeof endMonth !== 'undefined') { _a = [endMonth, endDay], endDay = _a[0], endMonth = _a[1]; } if (typeof endMonth === 'undefined') endMonth = beginMonth; if (typeof endDay === 'undefined') endDay = beginDay; _b = [endMonth, endDay], _this.endMonth = _b[0], _this.endDay = _b[1]; return _this; var _a, _b; } SeasonalOverride.prototype.shouldActivate = function () { var today = new Date(); var currentMonth = today.getMonth(); var currentDay = today.getDate(); if (currentMonth < this.beginMonth || currentMonth > this.endMonth) return false; if (currentMonth > this.beginMonth && currentMonth < this.endMonth) return true; if (currentMonth === this.beginMonth) return currentDay >= this.beginDay && (currentDay <= this.endDay || this.endMonth > this.beginMonth); if (currentMonth === this.endMonth) return (currentDay >= this.beginDay || this.beginMonth < this.endMonth) && currentDay <= this.endDay; return false; }; return SeasonalOverride; }(override_1.Override)); exports.SeasonalOverride = SeasonalOverride; //# sourceMappingURL=seasonal-override.js.map