UNPKG

onix-core

Version:
62 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatInterval = void 0; const i18n_1 = require("../../i18n"); const DateInterval_1 = require("./DateInterval"); const formatInterval = (interval, parts = 0) => { interval = DateInterval_1.normalize(interval); const format = []; if (interval.y !== 0) { format.push(i18n_1._("datetime", "years", { y: interval.y })); } else { format.push(false); } if (interval.m !== 0) { format.push(i18n_1._("datetime", "months", { m: interval.m })); } else { format.push(false); } if (interval.d !== 0) { format.push(i18n_1._("datetime", "days", { d: interval.d })); } else { format.push(false); } if (interval.h !== 0) { format.push(i18n_1._("datetime", "hours", { h: interval.h })); } else { format.push(false); } if (interval.i !== 0) { format.push(i18n_1._("datetime", "minutes", { i: interval.i })); } else { format.push(false); } if (interval.s !== 0) { format.push(i18n_1._("datetime", "seconds", { s: interval.s })); } else { format.push(false); } while ((format.length > 0) && !format[0]) { format.shift(); } if (format.length === 0) { return ""; } let values; if ((parts > 0) && (format.length > 1)) { const slice = format.slice(0, parts); values = slice.filter((a) => !!a); } else { values = format.filter((a) => !!a); } return values.join(" "); }; exports.formatInterval = formatInterval; //# sourceMappingURL=formatInterval.js.map