mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
refactor(format): consolidate duration formatters into format/formatDuration (Phase L, part 2) (#690)
The mm:ss track-time formatter was hand-rolled in 11 places and the h:mm:ss total-duration formatter in 4 — extract two tested functions: - formatTrackTime(seconds, fallback='0:00') — m:ss, used for track / playback times. fallback param covers the '–' placeholder rows. - formatLongDuration(seconds) — h:mm:ss when >=1h, else m:ss, used for album / queue totals. Behaviour preserved per call site: the unified guard (!seconds || !isFinite || <0 -> fallback) produces identical output to every prior variant for all real inputs; SongRow keeps its '–' via the fallback arg. Removes the formatter exports from 6 componentHelpers files (playerBarHelpers / fullscreenPlayerHelpers deleted — they only exported the formatter) and 7 inline component copies. + formatDuration.test.ts
This commit is contained in:
committed by
GitHub
parent
7a7a9f5e6b
commit
5231169a71
@@ -19,6 +19,7 @@ import OrbitSettingsPopover from './OrbitSettingsPopover';
|
||||
import OrbitSharePopover from './OrbitSharePopover';
|
||||
import OrbitDiagnosticsPopover from './OrbitDiagnosticsPopover';
|
||||
import ConfirmModal from './ConfirmModal';
|
||||
import { formatTrackTime } from '../utils/format/formatDuration';
|
||||
|
||||
/**
|
||||
* Orbit — top-strip session indicator.
|
||||
@@ -34,11 +35,9 @@ import ConfirmModal from './ConfirmModal';
|
||||
|
||||
const CATCH_UP_DRIFT_THRESHOLD_MS = 3_000;
|
||||
|
||||
/** `m:ss` countdown from a millisecond value. */
|
||||
function formatCountdown(ms: number): string {
|
||||
const clamped = Math.max(0, Math.round(ms / 1000));
|
||||
const m = Math.floor(clamped / 60);
|
||||
const s = clamped % 60;
|
||||
return `${m}:${s.toString().padStart(2, '0')}`;
|
||||
return formatTrackTime(Math.round(ms / 1000));
|
||||
}
|
||||
|
||||
export default function OrbitSessionBar() {
|
||||
|
||||
Reference in New Issue
Block a user