mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 17:03:53 +00:00
22 lines
727 B
TypeScript
22 lines
727 B
TypeScript
import type { OntimeEvent } from 'ontime-types';
|
|
|
|
import { dayInMs } from './conversionUtils.js';
|
|
|
|
/**
|
|
* Checks whether a new element is the latest in the list
|
|
*/
|
|
export function isNewLatest(
|
|
currentEvent: Pick<OntimeEvent, 'timeStart' | 'duration' | 'dayOffset'>,
|
|
previousEvent: Pick<OntimeEvent, 'timeStart' | 'duration' | 'dayOffset'> | null,
|
|
) {
|
|
// true if there is no previous
|
|
if (!previousEvent) {
|
|
return true;
|
|
}
|
|
|
|
const normalisedCurrentEnd = currentEvent.timeStart + currentEvent.duration + currentEvent.dayOffset * dayInMs;
|
|
const normalisedPreviousEnd = previousEvent.timeStart + previousEvent.duration + previousEvent.dayOffset * dayInMs;
|
|
|
|
return normalisedCurrentEnd >= normalisedPreviousEnd;
|
|
}
|