MCPcopy Create free account
hub / github.com/arctic-cli/interface / parseDateFilter

Function parseDateFilter

packages/arctic/src/cli/cmd/stats.ts:112–161  ·  view source on GitHub ↗
(date?: string, from?: string, to?: string)

Source from the content-addressed store, hash-verified

110}
111
112function parseDateFilter(date?: string, from?: string, to?: string): DateFilter | undefined {
113 const today = new Date()
114 today.setHours(0, 0, 0, 0)
115
116 if (date) {
117 if (date === "today") {
118 const end = new Date(today)
119 end.setHours(23, 59, 59, 999)
120 return { from: today, to: end, label: "today" }
121 }
122 if (date === "yesterday") {
123 const yesterday = new Date(today)
124 yesterday.setDate(yesterday.getDate() - 1)
125 const end = new Date(yesterday)
126 end.setHours(23, 59, 59, 999)
127 return { from: yesterday, to: end, label: "yesterday" }
128 }
129 const parsed = new Date(date)
130 if (!isNaN(parsed.getTime())) {
131 parsed.setHours(0, 0, 0, 0)
132 const end = new Date(parsed)
133 end.setHours(23, 59, 59, 999)
134 return { from: parsed, to: end, label: date }
135 }
136 console.error(`Invalid date format: ${date}. Use "today", "yesterday", or YYYY-MM-DD`)
137 process.exit(1)
138 }
139
140 if (from || to) {
141 const fromDate = from ? new Date(from) : new Date(0)
142 const toDate = to ? new Date(to) : new Date()
143
144 if (from && isNaN(fromDate.getTime())) {
145 console.error(`Invalid from date: ${from}. Use YYYY-MM-DD format`)
146 process.exit(1)
147 }
148 if (to && isNaN(toDate.getTime())) {
149 console.error(`Invalid to date: ${to}. Use YYYY-MM-DD format`)
150 process.exit(1)
151 }
152
153 fromDate.setHours(0, 0, 0, 0)
154 toDate.setHours(23, 59, 59, 999)
155
156 const label = from && to ? `${from} to ${to}` : from ? `from ${from}` : `until ${to}`
157 return { from: fromDate, to: toDate, label }
158 }
159
160 return undefined
161}
162
163function displayStats(stats: SessionStats, view: "all" | "overview" | "models" | "cost", dateFilter?: DateFilter) {
164 const daysToShow = calculateDaysToShow(stats)

Callers 1

stats.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected