Skip to content

Commit bf1bf89

Browse files
authored
Merge pull request #468 from rajbos/30-full-days
Prevent showing different 30 day numbers on reloads
2 parents 412c24b + 525258c commit bf1bf89

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cli/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export async function calculateDetailedStats(
250250
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
251251
const lastMonthStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
252252
const lastMonthEnd = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59);
253-
const last30DaysStart = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
253+
const last30DaysStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
254254

255255
const periods: {
256256
today: PeriodStats;
@@ -376,7 +376,7 @@ export async function calculateUsageAnalysisStats(sessionFiles: string[]): Promi
376376

377377
const now = new Date();
378378
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
379-
const last30DaysStart = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
379+
const last30DaysStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
380380
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
381381

382382
const todayPeriod = createEmptyUsageAnalysisPeriod();

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,8 @@ class CopilotTokenTracker implements vscode.Disposable {
734734
// Calculate Previous Month boundaries
735735
const lastMonthEnd = new Date(now.getFullYear(), now.getMonth(), 0, 23, 59, 59, 999); // Last day of previous month
736736
const lastMonthStart = new Date(lastMonthEnd.getFullYear(), lastMonthEnd.getMonth(), 1);
737-
// Calculate last 30 days boundary
738-
const last30DaysStart = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
737+
// Calculate last 30 days boundary (midnight, so numbers don't shift during a refresh)
738+
const last30DaysStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
739739

740740
const todayStats = { tokens: 0, thinkingTokens: 0, estimatedTokens: 0, actualTokens: 0, sessions: 0, interactions: 0, modelUsage: {} as ModelUsage, editorUsage: {} as EditorUsage };
741741
const monthStats = { tokens: 0, thinkingTokens: 0, estimatedTokens: 0, actualTokens: 0, sessions: 0, interactions: 0, modelUsage: {} as ModelUsage, editorUsage: {} as EditorUsage };
@@ -1243,7 +1243,7 @@ class CopilotTokenTracker implements vscode.Disposable {
12431243

12441244
const now = new Date();
12451245
const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
1246-
const last30DaysStart = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
1246+
const last30DaysStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
12471247
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
12481248

12491249
this.log('🔍 [Usage Analysis] Starting calculation...');

0 commit comments

Comments
 (0)