mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
28 lines
725 B
TypeScript
28 lines
725 B
TypeScript
import type { OntimeEvent } from 'ontime-types';
|
|
|
|
import { dayInMs } from './conversionUtils.js';
|
|
|
|
/**
|
|
* Utility function checks whether a given event is the day after from its predecessor
|
|
*/
|
|
export function checkIsNextDay(
|
|
current: Pick<OntimeEvent, 'timeStart' | 'dayOffset'>,
|
|
previous: Pick<OntimeEvent, 'timeStart' | 'duration' | 'dayOffset'> | null,
|
|
): boolean {
|
|
if (!previous) {
|
|
return false;
|
|
}
|
|
|
|
// if the day offsets are the same it can't be the next day
|
|
if (current.dayOffset <= previous.dayOffset) {
|
|
return false;
|
|
}
|
|
|
|
// if the previous event crossed midnight then the current is the same day
|
|
if (previous.timeStart + previous.duration > dayInMs) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|