UNPKG

nhb-toolbox

Version:

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

30 lines (29 loc) 893 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dayPartPlugin = void 0; const constants_1 = require("../constants"); const dayPartPlugin = ($Chronos) => { $Chronos.prototype.getPartOfDay = function (config) { const hour = this.hour; const ranges = { ...constants_1.DATE_PART_RANGES, ...config, }; for (const [part, [start, end]] of Object.entries(ranges)) { const from = Number(start); const to = Number(end); if (from <= to) { if (hour >= from && hour <= to) { return part; } } else { if (hour >= from || hour <= to) { return part; } } } return 'night'; }; }; exports.dayPartPlugin = dayPartPlugin;