mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 18:03:47 +00:00
@@ -1424,7 +1424,7 @@ describe('getRuntimeOffset()', () => {
|
||||
expect(offset).toBe(-50);
|
||||
});
|
||||
|
||||
it('added time adds time ahead (positive offset)', () => {
|
||||
it('added time subtracts time offset (positive offset)', () => {
|
||||
const state = {
|
||||
eventNow: {
|
||||
id: '1',
|
||||
@@ -1444,7 +1444,7 @@ describe('getRuntimeOffset()', () => {
|
||||
} as RuntimeState;
|
||||
|
||||
const offset = getRuntimeOffset(state);
|
||||
expect(offset).toBe(-40);
|
||||
expect(offset).toBe(-60);
|
||||
});
|
||||
|
||||
it('considers running overtime (negative offset)', () => {
|
||||
|
||||
@@ -322,10 +322,10 @@ export function getRuntimeOffset(state: RuntimeState): MaybeNumber {
|
||||
const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt;
|
||||
|
||||
// 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)
|
||||
// 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) {
|
||||
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;
|
||||
expect(newState.runtime.actualStart).toBe(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
|
||||
load(event2, [event1, event2]);
|
||||
@@ -177,13 +177,13 @@ describe('mutation on runtimeState', () => {
|
||||
const delayBefore = event2.timeStart - newState.clock;
|
||||
expect(newState.runtime.offset).toBe(delayBefore);
|
||||
// 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
|
||||
addTime(10);
|
||||
newState = getState();
|
||||
expect(newState.runtime.offset).toBe(delayBefore + 10);
|
||||
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd + newState.runtime.offset);
|
||||
expect(newState.runtime.offset).toBe(delayBefore - 10);
|
||||
expect(newState.runtime.expectedEnd).toBe(event2.timeEnd - newState.runtime.offset);
|
||||
|
||||
// 5. Stop event
|
||||
stop();
|
||||
|
||||
@@ -301,7 +301,7 @@ export function start(state: RuntimeState = runtimeState): boolean {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -389,6 +389,7 @@ export function update(): UpdateResult {
|
||||
|
||||
// update offset
|
||||
runtimeState.runtime.offset = getRuntimeOffset(runtimeState);
|
||||
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
|
||||
|
||||
return {
|
||||
hasTimerFinished,
|
||||
|
||||
Reference in New Issue
Block a user