"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.computeCashInvoiceExpiry = computeCashInvoiceExpiry; exports.earliestCashInvoiceExpiry = earliestCashInvoiceExpiry; const tehran_time_1 = require("./tehran-time"); function computeCashInvoiceExpiry(company) { const now = new Date(); if (company.cashInvoiceValidUntilHour != null && Number.isFinite(company.cashInvoiceValidUntilHour)) { const expires = (0, tehran_time_1.tehranAtHour)(now, company.cashInvoiceValidUntilHour); if (expires.getTime() <= now.getTime()) { return (0, tehran_time_1.tehranAtHour)((0, tehran_time_1.addDays)(now, 1), company.cashInvoiceValidUntilHour); } return expires; } return new Date(now.getTime() + company.cashInvoiceValidityHours * 60 * 60 * 1000); } function earliestCashInvoiceExpiry(companies) { if (!companies.length) { return new Date(Date.now() + 8 * 60 * 60 * 1000); } return companies .map((company) => computeCashInvoiceExpiry(company)) .reduce((earliest, current) => current.getTime() < earliest.getTime() ? current : earliest); } //# sourceMappingURL=cash-expiry.js.map