From 79f710948b6abea10a3c8246daf62f0ea568da36 Mon Sep 17 00:00:00 2001 From: Rassl Date: Sun, 14 Jun 2026 23:10:03 +0000 Subject: [PATCH] Generated with Hive: Fix formatCountdown to display HH:MM:SS for long invoice expiries --- src/lib/__tests__/format-countdown.test.ts | 12 ++++++++++++ src/lib/format-countdown.ts | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/__tests__/format-countdown.test.ts b/src/lib/__tests__/format-countdown.test.ts index 53b0537d..cacf8595 100644 --- a/src/lib/__tests__/format-countdown.test.ts +++ b/src/lib/__tests__/format-countdown.test.ts @@ -29,4 +29,16 @@ describe("formatCountdown", () => { it("floors fractional seconds", () => { expect(formatCountdown(90.9)).toBe("01:30") }) + + it('returns "01:00:00" for 3600 seconds', () => { + expect(formatCountdown(3600)).toBe("01:00:00") + }) + + it('returns "23:54:06" for 86046 seconds', () => { + expect(formatCountdown(86046)).toBe("23:54:06") + }) + + it('returns "01:30" for 90 seconds (unchanged MM:SS)', () => { + expect(formatCountdown(90)).toBe("01:30") + }) }) diff --git a/src/lib/format-countdown.ts b/src/lib/format-countdown.ts index 9eefc5b4..e0d3ff60 100644 --- a/src/lib/format-countdown.ts +++ b/src/lib/format-countdown.ts @@ -1,7 +1,11 @@ -/** Converts seconds into a "MM:SS" string (e.g. 90 → "01:30"). */ +/** Converts seconds into a "MM:SS" string (e.g. 90 → "01:30") or "HH:MM:SS" for durations ≥ 1 hour (e.g. 86046 → "23:54:06"). */ export function formatCountdown(seconds: number): string { const s = Math.max(0, Math.floor(seconds)) - const m = Math.floor(s / 60) + const h = Math.floor(s / 3600) + const m = Math.floor((s % 3600) / 60) const rem = s % 60 + if (h > 0) { + return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(rem).padStart(2, "0")}` + } return `${String(m).padStart(2, "0")}:${String(rem).padStart(2, "0")}` }