mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
refactor: gather group metadata
This commit is contained in:
+8
-12
@@ -1,11 +1,11 @@
|
||||
import { dayInMs, MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from './conversionUtils';
|
||||
import { getTimeFromPrevious } from './getTimeFromPrevious';
|
||||
import { getTimeFrom } from './getTimeFrom';
|
||||
|
||||
describe('getTimeFromPrevious', () => {
|
||||
describe('getTimeFrom', () => {
|
||||
it('returns the time elapsed (gap or overlap) from the previous', () => {
|
||||
const expected = 75600000 - 71700000; // current start - previousEnd
|
||||
expect(
|
||||
getTimeFromPrevious(
|
||||
getTimeFrom(
|
||||
{ timeStart: 21 * MILLIS_PER_HOUR, dayOffset: 0 },
|
||||
{ timeStart: 19 * MILLIS_PER_HOUR + 20 * MILLIS_PER_MINUTE, duration: 35 * MILLIS_PER_MINUTE, dayOffset: 0 },
|
||||
),
|
||||
@@ -14,22 +14,18 @@ describe('getTimeFromPrevious', () => {
|
||||
|
||||
it('accounts for partially overlapping events', () => {
|
||||
const expected = -1;
|
||||
expect(getTimeFromPrevious({ timeStart: 11, dayOffset: 0 }, { timeStart: 10, duration: 2, dayOffset: 0 })).toBe(
|
||||
expected,
|
||||
);
|
||||
expect(getTimeFrom({ timeStart: 11, dayOffset: 0 }, { timeStart: 10, duration: 2, dayOffset: 0 })).toBe(expected);
|
||||
});
|
||||
|
||||
it('accounts for events that are fully contained', () => {
|
||||
const expected = -6;
|
||||
expect(getTimeFromPrevious({ timeStart: 10, dayOffset: 0 }, { timeStart: 8, duration: 8, dayOffset: 0 })).toBe(
|
||||
expected,
|
||||
);
|
||||
expect(getTimeFrom({ timeStart: 10, dayOffset: 0 }, { timeStart: 8, duration: 8, dayOffset: 0 })).toBe(expected);
|
||||
});
|
||||
|
||||
it('fully overlapping events are the next day', () => {
|
||||
const expected = dayInMs - 2 * MILLIS_PER_HOUR;
|
||||
expect(
|
||||
getTimeFromPrevious(
|
||||
getTimeFrom(
|
||||
{ timeStart: 10 * MILLIS_PER_HOUR, dayOffset: 1 },
|
||||
{ timeStart: 10 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 },
|
||||
),
|
||||
@@ -39,7 +35,7 @@ describe('getTimeFromPrevious', () => {
|
||||
it('accounts for events that are the day after', () => {
|
||||
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
|
||||
expect(
|
||||
getTimeFromPrevious(
|
||||
getTimeFrom(
|
||||
{ timeStart: 22 * MILLIS_PER_HOUR, dayOffset: 0 },
|
||||
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 3 * MILLIS_PER_HOUR, dayOffset: 0 },
|
||||
),
|
||||
@@ -49,7 +45,7 @@ describe('getTimeFromPrevious', () => {
|
||||
it('accounts for events that cross midnight', () => {
|
||||
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
|
||||
expect(
|
||||
getTimeFromPrevious(
|
||||
getTimeFrom(
|
||||
{ timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 },
|
||||
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 },
|
||||
),
|
||||
+2
-2
@@ -3,9 +3,9 @@ import type { OntimeEvent } from 'ontime-types';
|
||||
import { dayInMs } from './conversionUtils.js';
|
||||
|
||||
/**
|
||||
* Utility returns the gap from previous event
|
||||
* Utility returns the gap from a previous given event
|
||||
*/
|
||||
export function getTimeFromPrevious(
|
||||
export function getTimeFrom(
|
||||
current: Pick<OntimeEvent, 'timeStart' | 'dayOffset'>,
|
||||
previous: Pick<OntimeEvent, 'timeStart' | 'duration' | 'dayOffset'> | null,
|
||||
): number {
|
||||
Reference in New Issue
Block a user