Files
ontime/packages/utils/src/date-utils/millisToString.ts
T
Carlos Valente 3603b836f6 refactor: cuesheet v2 (#435)
* refactor: typescript migration

* chore: remove prop-types package

* refactor: file structure

* refactor: migrate ontime table to tanstack table 8

* refactor: rundown controller uses service as data source

* refactor: convert to typescript

* feat: caching store

* refactor: add delay values to rundown

* feat: toggle past visibility

* chore: update tests

* refactor: add extra fields to CSV

* style: show skipped events

* chore: add route to navigation menu

* style: allow jumping to bottom

* chore: add tests
2023-07-22 09:32:40 +02:00

20 lines
679 B
TypeScript

import { DateTime } from 'luxon';
/**
* @description Converts milliseconds to string representing time
* @param {number | null} millis - time in milliseconds
* @param {boolean} showSeconds - weather to show the seconds
* @param {string} fallback - what to return if value is null
* @returns {string} String representing time 00:12:02
*/
export function millisToString(millis: number | null, showSeconds = true, fallback = '...') {
if (millis == null) {
return fallback;
}
const isNegative = millis < 0;
const format = `HH:mm${showSeconds ? ':ss' : ''}`;
return `${isNegative ? '-' : ''}${DateTime.fromMillis(Math.abs(millis)).toUTC().toFormat(format)}`;
}