diff options
| author | Thomas Grothe <grothe.tr@gmail.com> | 2026-04-30 00:53:13 -0400 |
|---|---|---|
| committer | Thomas Grothe <grothe.tr@gmail.com> | 2026-04-30 00:53:13 -0400 |
| commit | 73d75835e18a33c7f6c1b09bbcef93b16a7a9bfa (patch) | |
| tree | e079c6c45416333e29cf900831c07619a87d5c39 /web-timeplot/src/utils-format.js | |
| parent | a1c95e72bea26f554eb05916d6fc584927367159 (diff) | |
redo timeplot web
Diffstat (limited to 'web-timeplot/src/utils-format.js')
| -rw-r--r-- | web-timeplot/src/utils-format.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/web-timeplot/src/utils-format.js b/web-timeplot/src/utils-format.js new file mode 100644 index 0000000..f4eac88 --- /dev/null +++ b/web-timeplot/src/utils-format.js @@ -0,0 +1,22 @@ +export function formatDuration(ms) { + const totalSeconds = Math.max(0, ms / 1000); + if (totalSeconds < 60) { + return `${totalSeconds.toFixed(2)}s`; + } + + const minutes = Math.floor(totalSeconds / 60); + const seconds = totalSeconds % 60; + return `${minutes}m ${seconds.toFixed(1)}s`; +} + +export function formatWallClock(timestampMs) { + return new Intl.DateTimeFormat(undefined, { + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + }).format(new Date(timestampMs)); +} + +export function formatValue(value) { + return Number.isFinite(value) ? value.toFixed(3) : '—'; +} |
