diff --git a/apps/server/src/services/timerUtils.ts b/apps/server/src/services/timerUtils.ts index 4cf4f1bc7..892d18011 100644 --- a/apps/server/src/services/timerUtils.ts +++ b/apps/server/src/services/timerUtils.ts @@ -1,5 +1,5 @@ -import { isOntimeEvent, MaybeNumber, OntimeBlock, OntimeEvent, Rundown, TimerPhase } from 'ontime-types'; -import { calculateTimeUntilStart, dayInMs, isPlaybackActive } from 'ontime-utils'; +import { isOntimeEvent, MaybeNumber, OntimeBlock, Rundown, TimerPhase } from 'ontime-types'; +import { calculateTimeUntilStart, dayInMs, getLastEventNormal, isPlaybackActive } from 'ontime-utils'; import type { RuntimeState } from '../stores/runtimeState.js'; import { shouldCrashDev } from '../utils/development.js'; @@ -40,13 +40,15 @@ export function getExpectedBlockFinish(state: RuntimeState, rundown: Rundown): M isLinkedToLoaded = isLinkedToLoaded && entry.linkStart; } } - const lastEntry = entries[orderInBlock.at(-1)!] as OntimeEvent; + const { lastEvent } = getLastEventNormal(rundown.entries, orderInBlock); + if (!lastEvent) return null; + const { offsetMode, offset, plannedStart, actualStart } = state.runtime; const timeUntilLastEvent = calculateTimeUntilStart({ - timeStart: lastEntry.timeStart, - dayOffset: lastEntry.dayOffset, - delay: lastEntry.delay, + timeStart: lastEvent.timeStart, + dayOffset: lastEvent.dayOffset, + delay: lastEvent.delay, currentDay: eventNow.dayOffset, totalGap, isLinkedToLoaded, @@ -57,7 +59,7 @@ export function getExpectedBlockFinish(state: RuntimeState, rundown: Rundown): M actualStart, }); - return clock + timeUntilLastEvent + lastEntry.duration; + return clock + timeUntilLastEvent + lastEvent.duration; } /** diff --git a/apps/server/src/stores/runtimeState.ts b/apps/server/src/stores/runtimeState.ts index 430c93256..ba890bfc5 100644 --- a/apps/server/src/stores/runtimeState.ts +++ b/apps/server/src/stores/runtimeState.ts @@ -723,7 +723,7 @@ export function loadBlock(rundown: Rundown, state = runtimeState) { //we went into a new block - and it is different from the one we might have come from if ((state.blockNow != null && state.blockNow.id != currentBlockId) || state.blockNow == null) { - state.blockNow = { id: currentBlockId, startedAt: null, expectedEnd: null }; // the id is set here, the start time is set in other placed that handel starting events + state.blockNow = { id: currentBlockId, startedAt: null, expectedEnd: null }; // the id is set here, the start time is set when starting events } }