export const STAT_BLUE = '#5470c6'; export const STAT_GREEN = '#91cc75'; export const STAT_ORANGE = '#fac858'; export function getDefaultDateRange(): [Date, Date] { const today = new Date(); const oneMonthAgo = new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); return [oneMonthAgo, today]; } function toDate(v: Date | { toDate?: () => Date }): Date { if (v && typeof (v as { toDate?: () => Date }).toDate === 'function') { return (v as { toDate: () => Date }).toDate(); } return v as Date; } export function formatDateTimeRangeFromRangePicker( start: Date | { toDate?: () => Date }, end: Date | { toDate?: () => Date } ): { startTime: string; endTime: string } { const s = toDate(start); const e = toDate(end); const startDate = new Date(s); startDate.setHours(0, 0, 0, 0); const endDate = new Date(e); endDate.setHours(23, 59, 59, 999); return { startTime: formatDateTime(startDate), endTime: formatDateTime(endDate) }; } export function formatDateTime(date: Date): string { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, '0'); const d = String(date.getDate()).padStart(2, '0'); const h = String(date.getHours()).padStart(2, '0'); const min = String(date.getMinutes()).padStart(2, '0'); const sec = String(date.getSeconds()).padStart(2, '0'); return `${y}-${m}-${d} ${h}:${min}:${sec}`; } export function chartMinWidth(categories: number, perItem = 48) { return Math.max(360, categories * perItem); }