Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(queue): carry a rounded duration into the next unit (#10086)

kevinfd4699a00b61
diff --git a/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.test.ts b/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.test.ts
new file mode 100644
index 0000000000..bc279336e6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from 'vitest';
+
+import { formatDuration } from './formatDuration';
+
+const after = (seconds: number) => {
+ const start = new Date('2026-01-01T00:00:00.000Z');
+ return [start.toISOString(), new Date(start.getTime() + seconds * 1000).toISOString()] as const;
+};
+
+describe('formatDuration', () => {
+ it('formats seconds, minutes and hours', () => {
+ expect(formatDuration(...after(12.5))).toBe('12.50s');
+ expect(formatDuration(...after(270))).toBe('4m 30s');
+ expect(formatDuration(...after(3900))).toBe('1h 5m');
+ });
+
+ it('moves to the next unit when rounding reaches it', () => {
+ expect(formatDuration(...after(59.996))).toBe('1m 0s');
+ expect(formatDuration(...after(119.6))).toBe('2m 0s');
+ expect(formatDuration(...after(3599.6))).toBe('1h 0m');
+ });
+
+ it('returns null for missing or reversed timestamps', () => {
+ expect(formatDuration(null, '2026-01-01T00:00:00.000Z')).toBeNull();
+ expect(formatDuration(...after(-1))).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.ts b/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.ts
index 124f0c40ec..4a5b51e18c 100644
--- a/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.ts
+++ b/invokeai/frontend/webv2/src/features/queue/ui/formatDuration.ts
@@ -10,14 +10,19 @@ export const formatDuration = (startedAt?: string | null, completedAt?: string |
return null;
}
- if (seconds < 60) {
- return `${seconds.toFixed(2)}s`;
+ const fixed = seconds.toFixed(2);
+
+ // Compare the rounded label, not the raw value: 59.996s would print "60.00s".
+ if (Number(fixed) < 60) {
+ return `${fixed}s`;
}
- const minutes = Math.floor(seconds / 60);
+ // Round to whole seconds before splitting units, so 119.6s reads "2m 0s", not "1m 60s".
+ const total = Math.round(seconds);
+ const minutes = Math.floor(total / 60);
if (minutes < 60) {
- return `${minutes}m ${Math.round(seconds % 60)}s`;
+ return `${minutes}m ${total % 60}s`;
}
const hours = Math.floor(minutes / 60);