Format time left as fixed width

- Update calculateTimeRemaining to output fixed-width, printf-style time strings:
  include days when present, with days: "Xd HHh MMm SSs" or "HHh MMm SSs" or "MMm SSs" or "SSs" as appropriate
- Ensure widths are consistent to prevent dancing columns and reserve space accordingly

X-Lovable-Edit-ID: edt-07201840-3eab-45ba-859c-91f91fcf2d0d
This commit is contained in:
gpt-engineer-app[bot]
2026-01-11 15:57:46 +00:00

View File

@@ -135,18 +135,15 @@ export function calculateTimeRemaining(endDate: string): {
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;
// Pad numbers to 2 digits for consistent width
const pad = (n: number) => n.toString().padStart(2, '0');
// Fixed-width formatting: %3dd %2dh %2dm %2ds or %2dh %2dm %2ds
const pad2 = (n: number) => n.toString().padStart(2, '0');
const pad3 = (n: number) => n.toString().padStart(3, ' ');
let formatted: string;
if (days > 0) {
formatted = `${days}d ${pad(hours)}h ${pad(minutes)}m ${pad(seconds)}s`;
} else if (hours > 0) {
formatted = `${pad(hours)}h ${pad(minutes)}m ${pad(seconds)}s`;
} else if (minutes > 0) {
formatted = `${pad(minutes)}m ${pad(seconds)}s`;
formatted = `${pad3(days)}d ${pad2(hours)}h ${pad2(minutes)}m ${pad2(seconds)}s`;
} else {
formatted = `${pad(seconds)}s`;
formatted = `${pad2(hours)}h ${pad2(minutes)}m ${pad2(seconds)}s`;
}
// Status based on time remaining