mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
timer has formatted timetag
This commit is contained in:
@@ -4,10 +4,13 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { stringFromMillis } from '../utils/time.js';
|
||||||
|
|
||||||
export class Timer {
|
export class Timer {
|
||||||
clock = null;
|
clock = null;
|
||||||
duration = null;
|
duration = null;
|
||||||
current = null;
|
current = null;
|
||||||
|
timeTag = null;
|
||||||
secondaryTimer = null;
|
secondaryTimer = null;
|
||||||
_finishAt = null;
|
_finishAt = null;
|
||||||
_finishedAt = null;
|
_finishedAt = null;
|
||||||
@@ -133,8 +136,12 @@ export class Timer {
|
|||||||
|
|
||||||
// getObject
|
// getObject
|
||||||
getObject() {
|
getObject() {
|
||||||
|
// update timer
|
||||||
this.update();
|
this.update();
|
||||||
|
|
||||||
|
// update timetag
|
||||||
|
this.timeTag = stringFromMillis(this.current);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
clock: this.clock,
|
clock: this.clock,
|
||||||
running: Timer.toSeconds(this.current),
|
running: Timer.toSeconds(this.current),
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
export const stringFromMillis = (
|
||||||
|
ms,
|
||||||
|
showSeconds = true,
|
||||||
|
delim = ':',
|
||||||
|
ifNull = '...'
|
||||||
|
) => {
|
||||||
|
if (ms === null || isNaN(ms)) return ifNull;
|
||||||
|
const showWith0 = (value) => (value < 10 ? `0${value}` : value);
|
||||||
|
const hours = showWith0(Math.floor(((ms / (1000 * 60 * 60)) % 60) % 24));
|
||||||
|
const minutes = showWith0(Math.floor((ms / (1000 * 60)) % 60));
|
||||||
|
const seconds = showWith0(Math.floor((ms / 1000) % 60));
|
||||||
|
|
||||||
|
return showSeconds
|
||||||
|
? `${
|
||||||
|
parseInt(hours) ? `${hours}${delim}` : `00${delim}`
|
||||||
|
}${minutes}${delim}${seconds}`
|
||||||
|
: `${parseInt(hours) ? `${hours}` : '00'}${delim}${minutes}`;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user