Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

fix(ui): round duration to whole seconds before splitting minutes (#13)

Pedro Monteirocd4ba046d6b6
diff --git a/src/lib/logic.test.ts b/src/lib/logic.test.ts
index 3bd82b8..3c6aabf 100644
--- a/src/lib/logic.test.ts
+++ b/src/lib/logic.test.ts
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import {
activeOverrides, buildRequest, compareBase, diffPixels, emptyComposer, expansionPixels, expansionPreset, jobFraction, jobLabel, moveRef, needsPrompt, normalizeQuality, persistentAdvanced, pipelineSummary,
planPipeline, remainingSeconds, sizeForWidth, timeAgo, upscaleRequest, upscaleTargets, versionLabels, type Ref,
- neighbourAfterRemoval, previewIndex, formatBytes, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, expandToRatio, expandToSize, arcLayout,
+ neighbourAfterRemoval, previewIndex, formatBytes, formatDuration, installItemShort, installItemText, installProgress, installStep, installTimeLeft, timelineLinks, undoTarget, aspectLabel, parseRatio, sizeForRatio, expandToRatio, expandToSize, arcLayout,
} from "./logic";
import type { GenerationRecord, InstallItem, JobView, Plan } from "./types";
@@ -389,3 +389,14 @@ describe("gallery preview", () => {
expect(neighbourAfterRemoval(["a"], "x")).toBeNull();
});
});
+
+describe("formatDuration", () => {
+ it("rounds to whole seconds before splitting minutes", () => {
+ expect(formatDuration(0.2)).toBe("1s");
+ expect(formatDuration(59.4)).toBe("59s");
+ expect(formatDuration(59.6)).toBe("1m");
+ expect(formatDuration(119.6)).toBe("2m");
+ expect(formatDuration(125)).toBe("2m 5s");
+ expect(formatDuration(3900)).toBe("65m");
+ });
+});
diff --git a/src/lib/logic.ts b/src/lib/logic.ts
index a269fd1..6649419 100644
--- a/src/lib/logic.ts
+++ b/src/lib/logic.ts
@@ -441,10 +441,10 @@ export function planPipeline(plan: Plan): string {
}
export function formatDuration(s: number): string {
- if (s < 60) return `${Math.max(1, Math.round(s))}s`;
- const m = Math.floor(s / 60);
- const r = Math.round(s % 60);
- return r ? `${m}m ${r}s` : `${m}m`;
+ const t = Math.round(s);
+ if (t < 60) return `${Math.max(1, t)}s`;
+ const m = Math.floor(t / 60);
+ return t % 60 ? `${m}m ${t % 60}s` : `${m}m`;
}
/** Undo target for version `key`: the version it was made from (`from` is that image's