mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
refactor: roll mode
* chore: escalate stack trace to console * refactor: event finding in roll * docs: initial roll specification * refactor: call to roll * refactor: normalise index * refactor: roll into next event * refactor: hot reload on waiting to roll * refactor: wait to roll next
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { checkIsNow } from './checkIsNow';
|
||||
import { MILLIS_PER_HOUR } from './conversionUtils';
|
||||
|
||||
describe('checkIsNow()', () => {
|
||||
test('should return true if now is between timeStart and timeEnd', () => {
|
||||
const timeStart = 9;
|
||||
const timeEnd = 16;
|
||||
const now = 10;
|
||||
expect(checkIsNow(timeStart, timeEnd, now)).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false if now is before start', () => {
|
||||
const timeStart = 9;
|
||||
const timeEnd = 16;
|
||||
const now = 8;
|
||||
expect(checkIsNow(timeStart, timeEnd, now)).toBe(false);
|
||||
});
|
||||
|
||||
test('should return false if now is after end', () => {
|
||||
const timeStart = 9;
|
||||
const timeEnd = 16;
|
||||
const now = 20;
|
||||
expect(checkIsNow(timeStart, timeEnd, now)).toBe(false);
|
||||
});
|
||||
|
||||
test('should return true accounting for events that roll over midnight', () => {
|
||||
expect(checkIsNow(22 * MILLIS_PER_HOUR, 8 * MILLIS_PER_HOUR, 23 * MILLIS_PER_HOUR)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { dayInMs } from './conversionUtils.js';
|
||||
|
||||
/**
|
||||
* Utility function checks whether a given event should be playing now
|
||||
*/
|
||||
export function checkIsNow(timeStart: number, timeEnd: number, clock: number): boolean {
|
||||
const normalisedEnd = timeEnd < timeStart ? timeEnd + dayInMs : timeEnd;
|
||||
return timeStart <= clock && clock <= normalisedEnd;
|
||||
}
|
||||
Reference in New Issue
Block a user