Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: remove trailing space in human-readable duration labels (#17317)

Try everythingde28771511fa
diff --git a/web/src/utils/date.ts b/web/src/utils/date.ts
index 62f5dae05e..fc5ba80cdd 100644
--- a/web/src/utils/date.ts
+++ b/web/src/utils/date.ts
@@ -72,9 +72,9 @@ export function formatSecondsToHumanReadable(seconds: number): string {
const s = seconds % 60;
const formattedSeconds = s === 0 ? '0' : s.toFixed(3).replace(/\.?0+$/, '');
const parts = [];
- if (h > 0) parts.push(`${h}h `);
- if (m > 0) parts.push(`${m}m `);
+ if (h > 0) parts.push(`${h}h`);
+ if (m > 0) parts.push(`${m}m`);
if (s || parts.length === 0) parts.push(`${formattedSeconds}s`);
- return parts.join('');
+ return parts.join(' ');
}
diff --git a/web/src/utils/tests/date.test.ts b/web/src/utils/tests/date.test.ts
new file mode 100644
index 0000000000..9ef64dea2a
--- /dev/null
+++ b/web/src/utils/tests/date.test.ts
@@ -0,0 +1,34 @@
+import { formatSecondsToHumanReadable } from '../date';
+
+describe('formatSecondsToHumanReadable', () => {
+ test('formats sub-minute durations in seconds', () => {
+ expect(formatSecondsToHumanReadable(0)).toBe('0s');
+ expect(formatSecondsToHumanReadable(30)).toBe('30s');
+ });
+
+ test('strips trailing zeros from fractional seconds', () => {
+ expect(formatSecondsToHumanReadable(1.5)).toBe('1.5s');
+ });
+
+ test('does not emit a trailing space for whole minutes or hours', () => {
+ expect(formatSecondsToHumanReadable(60)).toBe('1m');
+ expect(formatSecondsToHumanReadable(3600)).toBe('1h');
+ expect(formatSecondsToHumanReadable(7200)).toBe('2h');
+ });
+
+ test('does not emit a trailing space when seconds are zero', () => {
+ expect(formatSecondsToHumanReadable(3660)).toBe('1h 1m');
+ expect(formatSecondsToHumanReadable(5400)).toBe('1h 30m');
+ });
+
+ test('joins non-zero hour/minute/second parts with a single space', () => {
+ expect(formatSecondsToHumanReadable(90)).toBe('1m 30s');
+ expect(formatSecondsToHumanReadable(125)).toBe('2m 5s');
+ expect(formatSecondsToHumanReadable(3661)).toBe('1h 1m 1s');
+ });
+
+ test('returns "0s" for negative or non-numeric input', () => {
+ expect(formatSecondsToHumanReadable(-5)).toBe('0s');
+ expect(formatSecondsToHumanReadable(NaN)).toBe('0s');
+ });
+});