summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-05-21 13:49:08 +0900
committerAdam Malczewski <[email protected]>2026-05-21 13:49:08 +0900
commitb0765ac2ad3461f7a2d575d4bd420bf05b043eda (patch)
tree324ec97018aeb5415043a7263360ee5a063f0610
parent772dcacccea48b1b814f9524a618564f2e909b2f (diff)
downloaddispatch-b0765ac2ad3461f7a2d575d4bd420bf05b043eda.tar.gz
dispatch-b0765ac2ad3461f7a2d575d4bd420bf05b043eda.zip
feat: natural English reset times beyond 48h (e.g. 'in 3w 2d (05/28)')
-rw-r--r--packages/frontend/src/lib/components/KeyUsage.svelte26
1 files changed, 24 insertions, 2 deletions
diff --git a/packages/frontend/src/lib/components/KeyUsage.svelte b/packages/frontend/src/lib/components/KeyUsage.svelte
index e7c6dee..f0f7d07 100644
--- a/packages/frontend/src/lib/components/KeyUsage.svelte
+++ b/packages/frontend/src/lib/components/KeyUsage.svelte
@@ -122,12 +122,34 @@
function formatDate(ts: number): string {
const diff = ts - Date.now();
- if (diff > 0 && diff < 48 * 60 * 60 * 1000) {
+ const days = Math.floor(diff / 86400000);
+ const d = new Date(ts);
+ const dateStr = d.toLocaleDateString("en-US", { month: "2-digit", day: "2-digit" });
+
+ if (diff <= 0) {
+ return d.toLocaleString();
+ }
+ if (diff < 48 * 60 * 60 * 1000) {
const hours = Math.floor(diff / 3600000);
const minutes = Math.floor((diff % 3600000) / 60000);
return `in ${hours}:${String(minutes).padStart(2, "0")}`;
}
- return new Date(ts).toLocaleString();
+ if (days <= 30) {
+ const weeks = Math.floor(days / 7);
+ const remDays = days % 7;
+ if (weeks > 0 && remDays > 0) {
+ return `in ${weeks}w ${remDays}d (${dateStr})`;
+ }
+ if (weeks > 0) {
+ return `in ${weeks} week${weeks > 1 ? "s" : ""} (${dateStr})`;
+ }
+ return `in ${days} day${days > 1 ? "s" : ""} (${dateStr})`;
+ }
+ return d.toLocaleDateString("en-US", {
+ month: "2-digit",
+ day: "2-digit",
+ year: "numeric",
+ });
}
function hasBucketData(bucket: UsageBucket | undefined): boolean {