mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 19:33:46 +00:00
fix: midnight roll (#484)
* refactor: extract utilities and types * refactor: extract and simplify progress bar logic * refactor: duration validation handles midnight * fix: prevent stale event loader * refactor: consider next event in timer invalidation * refactor: reload changes on changed roll target * refactor: timer load accounts for midnight * fix: issues with midnight on roll * refactor: prevent stale secondary event
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
type MaybeNumber = number | null;
|
||||
import { MaybeNumber } from 'ontime-types';
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
|
||||
/**
|
||||
* Calculates expected finish time of a running timer
|
||||
@@ -18,7 +19,14 @@ export function getExpectedFinish(
|
||||
return finishedAt;
|
||||
}
|
||||
|
||||
return Math.max(startedAt + duration + pausedTime + addedTime, startedAt);
|
||||
// handle events that finish the day after
|
||||
const expectedFinish = startedAt + duration + pausedTime + addedTime;
|
||||
if (expectedFinish > dayInMs) {
|
||||
return expectedFinish - dayInMs;
|
||||
}
|
||||
|
||||
// an event cannot finish before it started (user added too much negative time)
|
||||
return Math.max(expectedFinish, startedAt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,15 +42,23 @@ export function getCurrent(
|
||||
if (startedAt === null) {
|
||||
return null;
|
||||
}
|
||||
if (startedAt > clock) {
|
||||
return startedAt + duration + addedTime + pausedTime - clock - dayInMs;
|
||||
}
|
||||
return startedAt + duration + addedTime + pausedTime - clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates elapsed time
|
||||
*/
|
||||
export function getElapsed(startedAt: number, clock: number) {
|
||||
export function getElapsed(startedAt: number | null, clock: number): number | null {
|
||||
if (startedAt === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// we are in the day after
|
||||
if (startedAt > clock) {
|
||||
throw new Error('clock cannot be higher than startedAt');
|
||||
return dayInMs - startedAt + clock;
|
||||
}
|
||||
return clock - startedAt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user