UNPKG

manifest

Version:

Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard

55 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.computePeriodBoundaries = computePeriodBoundaries; exports.computePeriodResetDate = computePeriodResetDate; const fmt = (d) => d.toISOString().replace('T', ' ').replace('Z', '').slice(0, 19); function computePeriodBoundaries(period) { const now = new Date(); let start; switch (period) { case 'hour': start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours() - 1)); break; case 'day': start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())); break; case 'week': { const dayOfWeek = now.getUTCDay(); const monday = now.getUTCDate() - ((dayOfWeek + 6) % 7); start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), monday)); break; } case 'month': start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)); break; default: start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours() - 1)); } const end = new Date(now.getTime()); return { periodStart: fmt(start), periodEnd: fmt(end) }; } function computePeriodResetDate(period) { const now = new Date(); let reset; switch (period) { case 'hour': reset = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours() + 1)); break; case 'day': reset = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1)); break; case 'week': { const dayOfWeek = now.getUTCDay(); const daysUntilMonday = (8 - dayOfWeek) % 7 || 7; reset = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + daysUntilMonday)); break; } case 'month': reset = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1)); break; default: reset = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours() + 1)); } return fmt(reset); } //# sourceMappingURL=period.util.js.map