mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 03:13:47 +00:00
@@ -1,3 +1,14 @@
|
||||
export const DAYMS = 86400000;
|
||||
|
||||
/**
|
||||
* @description handle events that span over midnight
|
||||
* @param {num} start - When does the event start
|
||||
* @param {num} end - When does the event end
|
||||
* @returns {num} normalised time
|
||||
*/
|
||||
export const normaliseEndTime = (start, end) => (end < start ? end + DAYMS : end);
|
||||
|
||||
|
||||
/**
|
||||
* @description Sorts an array of objects by given property
|
||||
* @param {array} arr - array to be sorted
|
||||
@@ -41,8 +52,9 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
let nowFound = false;
|
||||
|
||||
// exit early if we are past the events
|
||||
const lastEventEnd = orderedEvents[orderedEvents.length - 1].timeEnd;
|
||||
if (now > lastEventEnd) {
|
||||
const lastEvent = orderedEvents[orderedEvents.length - 1];
|
||||
const lastNormalEnd = normaliseEndTime(lastEvent.timeStart, lastEvent.timeEnd);
|
||||
if (now > lastNormalEnd) {
|
||||
return {
|
||||
nowIndex,
|
||||
nowId,
|
||||
@@ -57,8 +69,7 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
// loop through events, look for where we should be
|
||||
for (const e of orderedEvents) {
|
||||
// When does the event end (handle midnight)
|
||||
const normalEnd =
|
||||
e.timeEnd < e.timeStart ? (e.timeEnd += this.DAYMS) : e.timeEnd;
|
||||
const normalEnd = normaliseEndTime(e.timeStart, e.timeEnd);
|
||||
|
||||
if (normalEnd <= now) {
|
||||
// event ran already
|
||||
@@ -83,7 +94,7 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
// set timers
|
||||
timers = {
|
||||
_startedAt: e.timeStart,
|
||||
_finishAt: normalEnd,
|
||||
_finishAt: e.timeEnd,
|
||||
duration: normalEnd - e.timeStart,
|
||||
current: normalEnd - now,
|
||||
};
|
||||
@@ -118,3 +129,4 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
timeToNext,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user