( range: StatsDateRange, )
| 716 | * For 'all', uses the cached aggregation. For other ranges, processes files directly. |
| 717 | */ |
| 718 | export async function aggregateClaudeCodeStatsForRange( |
| 719 | range: StatsDateRange, |
| 720 | ): Promise<ClaudeCodeStats> { |
| 721 | if (range === 'all') { |
| 722 | return aggregateClaudeCodeStats() |
| 723 | } |
| 724 | |
| 725 | const allSessionFiles = await getAllSessionFiles() |
| 726 | if (allSessionFiles.length === 0) { |
| 727 | return getEmptyStats() |
| 728 | } |
| 729 | |
| 730 | // Calculate fromDate based on range |
| 731 | const today = new Date() |
| 732 | const daysBack = range === '7d' ? 7 : 30 |
| 733 | const fromDate = new Date(today) |
| 734 | fromDate.setDate(today.getDate() - daysBack + 1) // +1 to include today |
| 735 | const fromDateStr = toDateString(fromDate) |
| 736 | |
| 737 | // Process session files for the date range |
| 738 | const stats = await processSessionFiles(allSessionFiles, { |
| 739 | fromDate: fromDateStr, |
| 740 | }) |
| 741 | |
| 742 | return processedStatsToClaudeCodeStats(stats) |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Convert ProcessedStats to ClaudeCodeStats. |
no test coverage detected