feat: count to end (#500)

This commit is contained in:
Carlos Valente
2023-08-27 19:25:40 +02:00
committed by GitHub
parent cd9dbcdc68
commit 5323e627fb
7 changed files with 259 additions and 23 deletions
+18 -1
View File
@@ -1,4 +1,4 @@
import { MaybeNumber } from 'ontime-types';
import { MaybeNumber, TimerType } from 'ontime-types';
import { dayInMs } from 'ontime-utils';
/**
@@ -10,6 +10,8 @@ export function getExpectedFinish(
duration: number,
pausedTime: number,
addedTime: number,
timeEnd: number,
timerType: TimerType,
) {
if (startedAt === null) {
return null;
@@ -19,6 +21,10 @@ export function getExpectedFinish(
return finishedAt;
}
if (timerType === TimerType.TimeToEnd) {
return timeEnd + addedTime + pausedTime;
}
// handle events that finish the day after
const expectedFinish = startedAt + duration + pausedTime + addedTime;
if (expectedFinish > dayInMs) {
@@ -38,11 +44,22 @@ export function getCurrent(
addedTime: number,
pausedTime: number,
clock: number,
timeEnd: number,
timerType: TimerType,
) {
if (startedAt === null) {
return null;
}
if (timerType === TimerType.TimeToEnd) {
if (startedAt > timeEnd) {
return timeEnd + addedTime + pausedTime + dayInMs - clock;
}
return timeEnd + addedTime + pausedTime - clock;
}
if (startedAt > clock) {
// we are the day after the event was started
return startedAt + duration + addedTime + pausedTime - clock - dayInMs;
}
return startedAt + duration + addedTime + pausedTime - clock;