mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
fix: delays account for midnight
This commit is contained in:
@@ -506,6 +506,7 @@ describe('getCurrent()', () => {
|
||||
timeStart: 79200000, // 22:00:00
|
||||
timeEnd: 600000, // 00:10:00
|
||||
countToEnd: true,
|
||||
dayOffset: 0,
|
||||
},
|
||||
clock: 79500000, // 22:05:00
|
||||
timer: {
|
||||
@@ -516,6 +517,7 @@ describe('getCurrent()', () => {
|
||||
rundown: {
|
||||
actualStart: 79200000,
|
||||
plannedEnd: 600000,
|
||||
currentDay: 0,
|
||||
},
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
@@ -527,6 +529,35 @@ describe('getCurrent()', () => {
|
||||
expect(current).toBe(dayInMs - 79500000 + 600000);
|
||||
});
|
||||
|
||||
it('handles overnight count-to-end after midnight', () => {
|
||||
const state = {
|
||||
eventNow: {
|
||||
timeStart: 23 * MILLIS_PER_HOUR, // 23:00:00
|
||||
timeEnd: 1 * MILLIS_PER_HOUR, // 01:00:00
|
||||
countToEnd: true,
|
||||
dayOffset: 0,
|
||||
},
|
||||
clock: 30 * MILLIS_PER_MINUTE, // 00:30:00 on day 1
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
duration: Infinity,
|
||||
startedAt: 23 * MILLIS_PER_HOUR,
|
||||
},
|
||||
rundown: {
|
||||
actualStart: 23 * MILLIS_PER_HOUR,
|
||||
plannedEnd: 1 * MILLIS_PER_HOUR,
|
||||
currentDay: 1,
|
||||
},
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
hasFinished: false,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const current = getCurrent(state);
|
||||
expect(current).toBe(30 * MILLIS_PER_MINUTE);
|
||||
});
|
||||
|
||||
it('handles events that were started late', () => {
|
||||
const state = {
|
||||
clock: 82000000, // 22:46:40 <--- starting 16 min after the scheduled end
|
||||
|
||||
@@ -77,9 +77,11 @@ export function getCurrent(state: RuntimeState): number {
|
||||
|
||||
if (countToEnd) {
|
||||
// count to end runs to its fixed end, so added time does not stretch the countdown
|
||||
const isEventOverMidnight = timeStart > timeEnd;
|
||||
const correctDay = isEventOverMidnight ? dayInMs : 0;
|
||||
return correctDay - clock + timeEnd;
|
||||
const dayOffset = state.eventNow.dayOffset ?? 0;
|
||||
const currentDay =
|
||||
state.rundown.currentDay ?? (timeStart > timeEnd && clock <= timeEnd ? dayOffset + 1 : dayOffset);
|
||||
const endDay = timeStart > timeEnd ? dayOffset + 1 : dayOffset;
|
||||
return timeEnd + endDay * dayInMs - (clock + currentDay * dayInMs);
|
||||
}
|
||||
|
||||
if (startedAt === null) {
|
||||
|
||||
Reference in New Issue
Block a user