Skip to content

Commit c32ff59

Browse files
committed
feat: add last-updated timestamp to hover tooltip
- Track lastUpdatedAt on each successful API fetch - Show "Updated at HH:mm:ss" (same day) or "Updated at yyyy-MM-dd HH:mm:ss" (cross-day) before the refresh icon in the hover tooltip - Add formatTimestamp() helper using local timezone
1 parent d8a2cb9 commit c32ff59

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/extension.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ let statusBarItem;
1010
let refreshTimer;
1111
/** @type {import('./api').UsageData | null} */
1212
let lastData = null;
13+
/** @type {Date | null} */
14+
let lastUpdatedAt = null;
1315
/** @type {boolean} */
1416
let refreshInFlight = false;
1517
/** @type {boolean} */
@@ -89,6 +91,7 @@ async function refresh(promptSignIn = false, isManual = false) {
8991

9092
const data = await fetchUsage(session.accessToken);
9193
lastData = data;
94+
lastUpdatedAt = new Date();
9295
updateStatusBar(data);
9396
} catch (err) {
9497
const code = err?.code;
@@ -135,7 +138,9 @@ function updateStatusBar(data, isRateLimited = false) {
135138
md.isTrusted = { enabledCommands: ['githubCopilotUsage.refresh'] };
136139
md.appendText(`No premium quota · Plan: ${data.plan}`);
137140
if (isRateLimited) md.appendMarkdown('\n\n_(Rate limited — showing last known data)_');
138-
md.appendMarkdown('\n\n[$(refresh)](command:githubCopilotUsage.refresh)');
141+
md.appendMarkdown('\n\n');
142+
if (lastUpdatedAt) md.appendMarkdown(`Updated at ${formatTimestamp(lastUpdatedAt)} `);
143+
md.appendMarkdown('[$(refresh)](command:githubCopilotUsage.refresh)');
139144
renderStatus({ text: '—', tooltip: md });
140145
return;
141146
}
@@ -198,10 +203,22 @@ function buildTooltip(data, isRateLimited) {
198203
md.appendMarkdown('_(Rate limited — showing last known data)_\n\n');
199204
}
200205

206+
if (lastUpdatedAt) md.appendMarkdown(`Updated at ${formatTimestamp(lastUpdatedAt)} `);
201207
md.appendMarkdown('[$(refresh)](command:githubCopilotUsage.refresh)');
202208
return md;
203209
}
204210

211+
/** @param {Date} date @returns {string} yyyy-MM-dd HH:mm:ss, or HH:mm:ss if today */
212+
function formatTimestamp(date) {
213+
const pad = (n) => String(n).padStart(2, '0');
214+
const now = new Date();
215+
const sameDay =
216+
date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
217+
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
218+
if (sameDay) return time;
219+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${time}`;
220+
}
221+
205222
function showLoading() {
206223
renderStatus({ text: '$(sync~spin)', tooltip: 'Loading Copilot usage…' });
207224
}

0 commit comments

Comments
 (0)