Relative run mode (#1512)

* inti relative mode

* send imediat update on mode change

* add relative to test

* don't persist offset mode

* add test relative and update calc function

* pass data from ssocket

* add dev guard

* spelling and comments

* show relative in offset overview

* remove comments

* refactor: move totalDelay to _rundown

* update  clear naming and comments

* remove old testing values
This commit is contained in:
Alex Christoffer Rasmussen
2025-04-19 21:36:54 +02:00
committed by GitHub
parent a94b10cb0f
commit dce87c3a81
17 changed files with 543 additions and 114 deletions
@@ -4,6 +4,7 @@ import { EndAction, Playback, TimeStrategy, TimerPhase, TimerType } from 'ontime
import {
getCurrent,
getExpectedFinish,
getRelativeOffset,
getRuntimeOffset,
getTimerPhase,
normaliseEndTime,
@@ -1046,6 +1047,84 @@ describe('getRuntimeOffset()', () => {
});
});
describe('getRelativeOffset()', () => {
it('relative offset is 0 when starting at the planed time', () => {
const state = {
eventNow: {
id: '1',
timeStart: 150,
},
timer: {
startedAt: 150,
addedTime: 0,
current: 0,
},
_timer: {
pausedAt: null,
},
runtime: {
actualStart: 150,
plannedStart: 150,
},
} as RuntimeState;
state.runtime.offset = getRuntimeOffset(state);
expect(state.runtime.offset).toBe(0);
const relativeOffsetoffset = getRelativeOffset(state);
expect(relativeOffsetoffset).toBe(0);
});
it('relative offset is 0 when starting after the planed time', () => {
const state = {
eventNow: {
id: '1',
timeStart: 100,
},
timer: {
startedAt: 150,
addedTime: 0,
current: 0,
},
_timer: {
pausedAt: null,
},
runtime: {
actualStart: 150,
plannedStart: 100,
},
} as RuntimeState;
state.runtime.offset = getRuntimeOffset(state);
expect(state.runtime.offset).toBe(-50);
const relativeOffsetoffset = getRelativeOffset(state);
expect(relativeOffsetoffset).toBe(0);
});
it('relative offset is 0 when starting before the planed time', () => {
const state = {
eventNow: {
id: '1',
timeStart: 150,
},
timer: {
startedAt: 100,
addedTime: 0,
current: 0,
},
_timer: {
pausedAt: null,
},
runtime: {
actualStart: 100,
plannedStart: 150,
},
} as RuntimeState;
state.runtime.offset = getRuntimeOffset(state);
expect(state.runtime.offset).toBe(50);
const relativeOffsetoffset = getRelativeOffset(state);
expect(relativeOffsetoffset).toBe(0);
});
});
describe('getTimerPhase()', () => {
it('should be None if the timer is not running', () => {
const state = {
@@ -1169,9 +1248,11 @@ describe('getTimerPhase()', () => {
},
_timer: {
forceFinish: null,
totalDelay: 0,
pausedAt: null,
},
_rundown: {
totalDelay: 0,
},
} as RuntimeState;
const phase = getTimerPhase(state);
@@ -1208,9 +1289,11 @@ describe('getTimerPhase()', () => {
},
_timer: {
forceFinish: null,
totalDelay: 0,
pausedAt: null,
},
_rundown: {
totalDelay: 0,
},
} as RuntimeState;
const phase = getTimerPhase(state);