Skip to content

Commit 4750e77

Browse files
Bump defu from 6.1.4 to 6.1.6 in the npm_and_yarn group across 1 directory (#332)
1 parent dd1426d commit 4750e77

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/services/github-copilot-usage-api.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,42 @@ export async function downloadReport(
500500
return response;
501501
}
502502

503+
const MS_PER_DAY = 24 * 60 * 60 * 1000;
504+
505+
function toDateString(date: Date): string {
506+
return date.toISOString().split('T')[0];
507+
}
508+
509+
/**
510+
* Shift all day_totals dates so the most recent day equals today.
511+
* Used in mock mode to keep mock data within the current date window,
512+
* regardless of the hardcoded dates in the static mock file.
513+
*/
514+
function shiftReportDatesToToday(report: OrgReport): OrgReport {
515+
if (!report.day_totals || report.day_totals.length === 0) return report;
516+
517+
const sorted = [...report.day_totals].sort((a, b) => a.day.localeCompare(b.day));
518+
const lastDay = sorted[sorted.length - 1].day;
519+
const today = toDateString(new Date());
520+
const daysDiff = Math.round(
521+
(new Date(today).getTime() - new Date(lastDay).getTime()) / MS_PER_DAY
522+
);
523+
524+
if (daysDiff <= 0) return report; // Data is already current
525+
526+
const shiftedTotals = sorted.map(d => {
527+
const shifted = new Date(new Date(d.day).getTime() + daysDiff * MS_PER_DAY);
528+
return { ...d, day: toDateString(shifted) };
529+
});
530+
531+
return {
532+
...report,
533+
report_start_day: shiftedTotals[0].day,
534+
report_end_day: shiftedTotals[shiftedTotals.length - 1].day,
535+
day_totals: shiftedTotals,
536+
};
537+
}
538+
503539
/**
504540
* Fetch the latest 28-day metrics report.
505541
* This is the most efficient endpoint — one API call + one download for 28 days of data.
@@ -525,6 +561,12 @@ export async function fetchLatestReport(
525561
merged.day_totals = reports.flatMap(r => r.day_totals);
526562
}
527563

564+
// In mock mode, shift dates to be relative to today so they fall within
565+
// the default "last 30 days" window used by sync-status and other queries.
566+
if (isMockMode()) {
567+
return shiftReportDatesToToday(merged);
568+
}
569+
528570
return merged;
529571
}
530572

0 commit comments

Comments
 (0)