fix: handle multiple days

This commit is contained in:
Carlos Valente
2024-08-28 19:00:14 +02:00
committed by Carlos Valente
parent f8ca5b9cef
commit db8ed93d41
5 changed files with 29 additions and 22 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export function isOntimeEvent(event: MaybeEvent): event is OntimeEvent {
}
export function isPlayableEvent(event: OntimeEvent): event is PlayableEvent {
return !event.skip;
return !event?.skip;
}
export function isOntimeDelay(event: MaybeEvent): event is OntimeDelay {
@@ -57,4 +57,11 @@ describe('checkIsNextDay', () => {
const timeStart = 2 * MILLIS_PER_HOUR;
expect(checkIsNextDay(previousStart, timeStart, previousDuration)).toBeTruthy();
});
it('should account for normalised start over multiple days', () => {
const previousStart = 90000000; // 25:00:00
const previousDuration = 1 * MILLIS_PER_HOUR;
const timeStart = 0;
expect(checkIsNextDay(previousStart, timeStart, previousDuration)).toBeTruthy();
});
});
@@ -24,8 +24,9 @@ export function checkIsNextDay(previousStart: number, timeStart: number, previou
return false;
}
if (timeStart <= previousStart) {
const normalisedPreviousEnd = previousStart + previousDuration;
const cappedStart = previousStart % dayInMs;
if (timeStart <= cappedStart) {
const normalisedPreviousEnd = cappedStart + previousDuration;
if (normalisedPreviousEnd === dayInMs) {
return true;
}