mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 07:53:54 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 281b1649fe | |||
| 652fe25fd1 |
@@ -1,4 +1,4 @@
|
|||||||
import { OntimeEvent, SupportedEvent } from 'ontime-types';
|
import { isOntimeEvent, OntimeEvent, SupportedEvent } from 'ontime-types';
|
||||||
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils';
|
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||||
|
|
||||||
import { loadRoll } from '../rollUtils.js';
|
import { loadRoll } from '../rollUtils.js';
|
||||||
@@ -246,6 +246,79 @@ describe('loadRoll() handle edge cases with midnight', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('loadRoll() handle rundowns with several days', () => {
|
||||||
|
it('should find the correct event, when we have many days', () => {
|
||||||
|
const now = 11 * MILLIS_PER_HOUR + 30 * MILLIS_PER_MINUTE;
|
||||||
|
const timedEvents = [
|
||||||
|
{
|
||||||
|
id: '0',
|
||||||
|
timeStart: 10 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 11 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
timeStart: 11 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 12 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
timeStart: 12 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 13 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4',
|
||||||
|
timeStart: 11 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 12 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const state = loadRoll(prepareTimedEvents(timedEvents), now);
|
||||||
|
const expected = {
|
||||||
|
event: timedEvents[1],
|
||||||
|
index: 1,
|
||||||
|
};
|
||||||
|
expect(state).toMatchObject(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should find the correct event, when we have events of zero duration', () => {
|
||||||
|
const now = 20 * MILLIS_PER_HOUR + 37 * MILLIS_PER_MINUTE;
|
||||||
|
const timedEvents = [
|
||||||
|
{
|
||||||
|
id: '0',
|
||||||
|
timeStart: 18 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 19 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '1 no duration',
|
||||||
|
timeStart: 0,
|
||||||
|
timeEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
timeStart: 19 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 20 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3 no duration',
|
||||||
|
timeStart: 0,
|
||||||
|
timeEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4',
|
||||||
|
timeStart: 20 * MILLIS_PER_HOUR,
|
||||||
|
timeEnd: 21 * MILLIS_PER_HOUR,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const state = loadRoll(prepareTimedEvents(timedEvents), now);
|
||||||
|
const expected = {
|
||||||
|
event: timedEvents[4],
|
||||||
|
index: 4,
|
||||||
|
};
|
||||||
|
expect(state).toMatchObject(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('loadRoll() handle edge cases with before and after start', () => {
|
describe('loadRoll() handle edge cases with before and after start', () => {
|
||||||
it('should prepare first event, if we are not yet in the rundown start', () => {
|
it('should prepare first event, if we are not yet in the rundown start', () => {
|
||||||
const now = 7 * MILLIS_PER_HOUR;
|
const now = 7 * MILLIS_PER_HOUR;
|
||||||
@@ -302,7 +375,7 @@ describe('loadRoll() handle edge cases with before and after start', () => {
|
|||||||
index: 0,
|
index: 0,
|
||||||
};
|
};
|
||||||
const state = loadRoll(singleEventList, now);
|
const state = loadRoll(singleEventList, now);
|
||||||
expect(state.isPending).toBeUndefined();
|
expect(state.isPending).toBeUndefined(); // we are playing the event
|
||||||
expect(state).toStrictEqual(expected);
|
expect(state).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -443,6 +516,7 @@ describe('loadRoll() test that roll behaviour multi day event edge cases', () =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
const state = loadRoll(eventlist, now);
|
const state = loadRoll(eventlist, now);
|
||||||
|
expect(state.isPending).toBeUndefined(); // we are playing the event
|
||||||
expect(state).toStrictEqual(expected);
|
expect(state).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,26 +15,11 @@ export function loadRoll(
|
|||||||
isPending?: boolean;
|
isPending?: boolean;
|
||||||
} {
|
} {
|
||||||
const { firstEvent } = getFirstEvent(timedEvents);
|
const { firstEvent } = getFirstEvent(timedEvents);
|
||||||
const { lastEvent } = getLastEvent(timedEvents);
|
|
||||||
|
|
||||||
if (!firstEvent || !lastEvent) {
|
if (!firstEvent) {
|
||||||
return { event: null, index: null };
|
return { event: null, index: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the rundown wraps around midnight
|
|
||||||
const wrapsAroundMidnight = firstEvent.timeStart > lastEvent.timeEnd;
|
|
||||||
|
|
||||||
if (!wrapsAroundMidnight) {
|
|
||||||
// check whether we are before or after the rundown
|
|
||||||
const lastNormalEnd = normaliseEndTime(lastEvent.timeStart, lastEvent.timeEnd);
|
|
||||||
const isAfterRundown = timeNow > lastNormalEnd;
|
|
||||||
const isBeforeRundown = timeNow < firstEvent.timeStart && !isAfterRundown;
|
|
||||||
|
|
||||||
if (isAfterRundown || isBeforeRundown) {
|
|
||||||
return { event: firstEvent, index: 0, isPending: true };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we know we are in the middle of the rundown and we need to find the current event
|
// we know we are in the middle of the rundown and we need to find the current event
|
||||||
// account for number of times we went over midnight
|
// account for number of times we went over midnight
|
||||||
let daySpan = 0;
|
let daySpan = 0;
|
||||||
@@ -46,6 +31,10 @@ export function loadRoll(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.duration === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// we check if event crosses midnight
|
// we check if event crosses midnight
|
||||||
if (event.timeStart > event.timeEnd) {
|
if (event.timeStart > event.timeEnd) {
|
||||||
daySpan++;
|
daySpan++;
|
||||||
|
|||||||
Reference in New Issue
Block a user