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:
Carlos Valente
2024-08-04 21:34:01 +02:00
committed by GitHub
parent 3012d73285
commit da11ef64c2
21 changed files with 1093 additions and 982 deletions
@@ -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;
}