UNPKG

gemini-cost-tracker

Version:

CLI tool to display token usage and costs for Gemini and Vertex AI

54 lines 1.64 kB
export function formatDate(date) { return date.toISOString().split('T')[0]; } export function formatDateTime(date) { if (!date) { return ''; } return date.toISOString().replace('T', ' ').substring(0, 19); } export function getDateRange(period) { const now = new Date(); const end = new Date(now); let start; switch (period) { case 'today': start = new Date(now); start.setHours(0, 0, 0, 0); end.setHours(23, 59, 59, 999); break; case 'week': start = new Date(now); start.setDate(now.getDate() - 7); start.setHours(0, 0, 0, 0); end.setHours(23, 59, 59, 999); break; case 'month': start = new Date(now); start.setDate(now.getDate() - 30); start.setHours(0, 0, 0, 0); end.setHours(23, 59, 59, 999); break; default: throw new Error(`Invalid period: ${period}`); } return { start, end }; } export function isValidDateString(dateString) { const regex = /^\d{4}-\d{2}-\d{2}$/; if (!regex.test(dateString)) { return false; } const date = new Date(dateString); return !isNaN(date.getTime()); } export function addDays(date, days) { const result = new Date(date); result.setDate(result.getDate() + days); return result; } export function getDaysDifference(startDate, endDate) { const timeDifference = endDate.getTime() - startDate.getTime(); return Math.ceil(timeDifference / (1000 * 3600 * 24)); } //# sourceMappingURL=dateHelper.js.map