fix #984 Expected End of timeline is not calculated correctly (#985)

This commit is contained in:
Leon Eckardt
2024-05-20 22:28:23 +02:00
committed by GitHub
parent 036d4051fc
commit 97b8e6a290
4 changed files with 11 additions and 10 deletions
@@ -1424,7 +1424,7 @@ describe('getRuntimeOffset()', () => {
expect(offset).toBe(-50); expect(offset).toBe(-50);
}); });
it('added time adds time ahead (positive offset)', () => { it('added time subtracts time offset (positive offset)', () => {
const state = { const state = {
eventNow: { eventNow: {
id: '1', id: '1',
@@ -1444,7 +1444,7 @@ describe('getRuntimeOffset()', () => {
} as RuntimeState; } as RuntimeState;
const offset = getRuntimeOffset(state); const offset = getRuntimeOffset(state);
expect(offset).toBe(-40); expect(offset).toBe(-60);
}); });
it('considers running overtime (negative offset)', () => { it('considers running overtime (negative offset)', () => {
+3 -3
View File
@@ -322,10 +322,10 @@ export function getRuntimeOffset(state: RuntimeState): MaybeNumber {
const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt; const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt;
// startOffset - difference between scheduled start and actual start // startOffset - difference between scheduled start and actual start
// addedTime - time added by user (positive offset) // addedTime - time added by user (negative offset)
// pausedTime - time the playback was paused (negative offset) // pausedTime - time the playback was paused (negative offset)
// overtime - how long the timer has been over-running (negative offset) // overtime - how long the timer has been over-running (negative offset)
return startOffset + addedTime - pausedTime - overtime; return startOffset - addedTime - pausedTime - overtime;
} }
/** /**
@@ -356,5 +356,5 @@ export function getExpectedEnd(state: RuntimeState): MaybeNumber {
if (state.runtime.actualStart === null) { if (state.runtime.actualStart === null) {
return null; return null;
} }
return state.runtime.plannedEnd + state.runtime.offset + state._timer.totalDelay; return state.runtime.plannedEnd - state.runtime.offset + state._timer.totalDelay;
} }
@@ -162,7 +162,7 @@ describe('mutation on runtimeState', () => {
const firstStart = newState.clock; const firstStart = newState.clock;
expect(newState.runtime.actualStart).toBe(newState.clock); expect(newState.runtime.actualStart).toBe(newState.clock);
expect(newState.runtime.offset).toBe(event1.timeStart - newState.clock); expect(newState.runtime.offset).toBe(event1.timeStart - newState.clock);
expect(newState.runtime.expectedEnd).toBe(newState.runtime.offset + event2.timeEnd); expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
// 3. Next event // 3. Next event
load(event2, [event1, event2]); load(event2, [event1, event2]);
@@ -177,13 +177,13 @@ describe('mutation on runtimeState', () => {
const delayBefore = event2.timeStart - newState.clock; const delayBefore = event2.timeStart - newState.clock;
expect(newState.runtime.offset).toBe(delayBefore); expect(newState.runtime.offset).toBe(delayBefore);
// finish is the difference between the runtime and the schedule // finish is the difference between the runtime and the schedule
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd + newState.runtime.offset); expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
// 4. Add time // 4. Add time
addTime(10); addTime(10);
newState = getState(); newState = getState();
expect(newState.runtime.offset).toBe(delayBefore + 10); expect(newState.runtime.offset).toBe(delayBefore - 10);
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd + newState.runtime.offset); expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
// 5. Stop event // 5. Stop event
stop(); stop();
+2 -1
View File
@@ -301,7 +301,7 @@ export function start(state: RuntimeState = runtimeState): boolean {
} }
state.runtime.offset = getRuntimeOffset(state); state.runtime.offset = getRuntimeOffset(state);
state.runtime.expectedEnd = state.runtime.plannedEnd + state.runtime.offset; state.runtime.expectedEnd = state.runtime.plannedEnd - state.runtime.offset;
return true; return true;
} }
@@ -389,6 +389,7 @@ export function update(): UpdateResult {
// update offset // update offset
runtimeState.runtime.offset = getRuntimeOffset(runtimeState); runtimeState.runtime.offset = getRuntimeOffset(runtimeState);
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
return { return {
hasTimerFinished, hasTimerFinished,