mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 14:14:17 +00:00
refactor: added time is time ahead
This commit is contained in:
committed by
Carlos Valente
parent
74418ce17e
commit
8b5034efbf
@@ -1401,7 +1401,7 @@ describe('updateRoll()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('getRuntimeOffset()', () => {
|
describe('getRuntimeOffset()', () => {
|
||||||
it('calculates the difference between schedule and actual start', () => {
|
it('is the difference between scheduled and when we actually started', () => {
|
||||||
const state = {
|
const state = {
|
||||||
eventNow: {
|
eventNow: {
|
||||||
id: '1',
|
id: '1',
|
||||||
@@ -1409,7 +1409,7 @@ describe('getRuntimeOffset()', () => {
|
|||||||
},
|
},
|
||||||
timer: {
|
timer: {
|
||||||
startedAt: 150,
|
startedAt: 150,
|
||||||
addedTime: 10,
|
addedTime: 0,
|
||||||
current: 0,
|
current: 0,
|
||||||
},
|
},
|
||||||
_timer: {
|
_timer: {
|
||||||
@@ -1421,10 +1421,33 @@ describe('getRuntimeOffset()', () => {
|
|||||||
} as RuntimeState;
|
} as RuntimeState;
|
||||||
|
|
||||||
const offset = getRuntimeOffset(state);
|
const offset = getRuntimeOffset(state);
|
||||||
expect(offset).toBe(60);
|
expect(offset).toBe(50);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('adds the overtime time of the current timer', () => {
|
it('added time adds time ahead (negative offset)', () => {
|
||||||
|
const state = {
|
||||||
|
eventNow: {
|
||||||
|
id: '1',
|
||||||
|
timeStart: 100,
|
||||||
|
},
|
||||||
|
timer: {
|
||||||
|
startedAt: 150,
|
||||||
|
addedTime: 10,
|
||||||
|
current: 10,
|
||||||
|
},
|
||||||
|
_timer: {
|
||||||
|
pausedAt: null,
|
||||||
|
},
|
||||||
|
runtime: {
|
||||||
|
actualStart: 150,
|
||||||
|
},
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
const offset = getRuntimeOffset(state);
|
||||||
|
expect(offset).toBe(40);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('considers running overtime (positive offset)', () => {
|
||||||
const state = {
|
const state = {
|
||||||
eventNow: {
|
eventNow: {
|
||||||
id: '1',
|
id: '1',
|
||||||
@@ -1432,9 +1455,9 @@ describe('getRuntimeOffset()', () => {
|
|||||||
timeEnd: 140,
|
timeEnd: 140,
|
||||||
},
|
},
|
||||||
timer: {
|
timer: {
|
||||||
startedAt: 100,
|
startedAt: 100, // we started ontime
|
||||||
current: -10,
|
current: -10, // we are 10 seconds over
|
||||||
addedTime: 0,
|
addedTime: 0, // we have not compensated with added time
|
||||||
},
|
},
|
||||||
_timer: {
|
_timer: {
|
||||||
pausedAt: null,
|
pausedAt: null,
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ export function getRuntimeOffset(state: RuntimeState): MaybeNumber {
|
|||||||
const startOffset = startedAt - timeStart;
|
const startOffset = startedAt - timeStart;
|
||||||
const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt;
|
const pausedTime = state._timer.pausedAt === null ? 0 : clock - state._timer.pausedAt;
|
||||||
|
|
||||||
return startOffset + addedTime + pausedTime + overtime;
|
return startOffset - addedTime + pausedTime + overtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user