feat: elapsed + drift formatting helpers

This commit is contained in:
2026-07-20 13:58:49 +01:00
parent c01917d38a
commit 80c8ecb5c8
2 changed files with 29 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
export function fmtElapsed(ms) {
const total = Math.floor(ms / 1000);
const h = Math.floor(total / 3600);
const m = Math.floor((total % 3600) / 60);
return `${h}:${String(m).padStart(2, '0')}`;
}
export function fmtDrift(driftMin) {
if (driftMin == null) return '';
const r = Math.round(driftMin);
if (r === 0) return 'on time';
return r > 0 ? `+${r} behind` : `${Math.abs(r)} ahead`;
}
+16
View File
@@ -0,0 +1,16 @@
import { describe, it, expect } from 'vitest';
import { fmtElapsed, fmtDrift } from '../../src/core/format.js';
describe('formatting', () => {
it('formats elapsed time', () => {
expect(fmtElapsed(0)).toBe('0:00');
expect(fmtElapsed(65 * 1000)).toBe('0:01');
expect(fmtElapsed(112 * 60 * 1000)).toBe('1:52');
});
it('formats drift with direction', () => {
expect(fmtDrift(null)).toBe('');
expect(fmtDrift(0)).toBe('on time');
expect(fmtDrift(6)).toBe('+6 behind');
expect(fmtDrift(-3)).toBe('3 ahead');
});
});