UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

42 lines (41 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.seasonPlugin = void 0; const seasons_1 = require("../seasons"); const seasonPlugin = ($Chronos) => { $Chronos.prototype.season = function (options) { const { preset = 'default' } = options ?? {}; const seasonSet = options?.seasons ?? seasons_1.SEASON_PRESETS[preset]; const dateStr = this.format('MM-DD'); for (const { name, boundary } of seasonSet) { if ('startDate' in boundary && 'endDate' in boundary) { const start = boundary.startDate; const end = boundary.endDate; if (start <= end) { if (dateStr >= start && dateStr <= end) return name; } else { if (dateStr >= start || dateStr <= end) return name; } } else if ('startMonth' in boundary && 'endMonth' in boundary) { const { startMonth, endMonth } = boundary; if (startMonth <= endMonth) { if (this.month >= startMonth && this.month <= endMonth) return name; } else { if (this.month >= startMonth || this.month <= endMonth) return name; } } } return 'Unknown'; }; $Chronos.prototype.getSeasonName = function (options) { return this.season(options); }; }; exports.seasonPlugin = seasonPlugin;