Refactor: better rounding (#1594)

This commit is contained in:
Alex Christoffer Rasmussen
2025-06-05 06:13:49 +02:00
committed by arc-alex
parent 421183fe55
commit 33ac05ebee
10 changed files with 93 additions and 181 deletions
@@ -1,4 +1,4 @@
import type { MaybeNumber } from 'ontime-types';
import type { MaybeNumber, TimerType } from 'ontime-types';
import { millisToSeconds, secondsToHours, secondsToMinutes } from './conversionUtils.js';
@@ -8,6 +8,7 @@ export function pad(val: number): string {
type FormatOptions = {
fallback?: string;
direction?: TimerType.CountDown | TimerType.CountUp;
};
/**
@@ -23,7 +24,7 @@ export function millisToString(millis?: MaybeNumber, options?: FormatOptions): s
const isNegative = millis < 0;
const totalSeconds = Math.abs(millisToSeconds(millis));
const totalSeconds = Math.abs(millisToSeconds(millis, options?.direction));
const seconds = totalSeconds % 60;
const minutes = secondsToMinutes(totalSeconds) % 60;
const hours = secondsToHours(totalSeconds);