Files
ontime/apps/client/src/common/utils/offset.ts
T
Alex Christoffer Rasmussen e0149c1cbf Invert overtime (#1715)
* refactor: invert offset calculation

* chore: update tests

* chore: flip offset in UI

* fix seconds display on group target duration

* update comment

* fix rebase
2025-08-18 06:16:53 +02:00

27 lines
720 B
TypeScript

import { MaybeNumber } from 'ontime-types';
import { millisToString } from 'ontime-utils';
import { enDash } from './styleUtils';
/**
* Formats offset text
*/
export function getOffsetText(offset: MaybeNumber): string {
if (offset === null) {
return enDash;
}
let offsetText = '';
if (offset < 0) offsetText += '-';
if (offset > 0) offsetText += '+';
offsetText += millisToString(Math.abs(offset));
return offsetText;
}
export function getOffsetState(offset: MaybeNumber): 'over' | 'under' | 'muted' | null {
if (offset === null) return 'muted';
if (offset === 0) return null;
// a positive value means that we are in over time aka behind schedule
return offset > 0 ? 'over' : 'under';
}