mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
fix: delays account for midnight
This commit is contained in:
committed by
Carlos Valente
parent
c8760b5e9c
commit
0c84a3ff9e
@@ -3,6 +3,7 @@ import {
|
|||||||
MILLIS_PER_HOUR,
|
MILLIS_PER_HOUR,
|
||||||
MILLIS_PER_MINUTE,
|
MILLIS_PER_MINUTE,
|
||||||
MILLIS_PER_SECOND,
|
MILLIS_PER_SECOND,
|
||||||
|
dayInMs,
|
||||||
formatFromMillis,
|
formatFromMillis,
|
||||||
getExpectedStart,
|
getExpectedStart,
|
||||||
} from 'ontime-utils';
|
} from 'ontime-utils';
|
||||||
@@ -29,6 +30,11 @@ export function nowInMillis(): number {
|
|||||||
return elapsed;
|
return elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normaliseWallClock(time: number): number {
|
||||||
|
const timeOfDay = time % dayInMs;
|
||||||
|
return timeOfDay < 0 ? timeOfDay + dayInMs : timeOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Resolves format from url and store
|
* @description Resolves format from url and store
|
||||||
* @return {string|null} A format string like "hh:mm:ss a" or null
|
* @return {string|null} A format string like "hh:mm:ss a" or null
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Switch from '../../../../common/components/switch/Switch';
|
|||||||
import Tooltip from '../../../../common/components/tooltip/Tooltip';
|
import Tooltip from '../../../../common/components/tooltip/Tooltip';
|
||||||
import { useEntryActionsContext } from '../../../../common/context/EntryActionsContext';
|
import { useEntryActionsContext } from '../../../../common/context/EntryActionsContext';
|
||||||
import { millisToDelayString } from '../../../../common/utils/dateConfig';
|
import { millisToDelayString } from '../../../../common/utils/dateConfig';
|
||||||
import { formatTime } from '../../../../common/utils/time';
|
import { formatTime, normaliseWallClock } from '../../../../common/utils/time';
|
||||||
import TimeInputFlow from '../../time-input-flow/TimeInputFlow';
|
import TimeInputFlow from '../../time-input-flow/TimeInputFlow';
|
||||||
|
|
||||||
import style from '../EntryEditor.module.scss';
|
import style from '../EntryEditor.module.scss';
|
||||||
@@ -68,8 +68,10 @@ function EventEditorTimes({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const hasDelay = delay !== 0;
|
const hasDelay = delay !== 0;
|
||||||
|
const delayedStart = normaliseWallClock(timeStart + delay);
|
||||||
|
const delayedEnd = normaliseWallClock(timeEnd + delay);
|
||||||
const delayLabel = hasDelay
|
const delayLabel = hasDelay
|
||||||
? `Event is ${millisToDelayString(delay, 'expanded')}. New schedule ${formatTime(timeStart + delay)} → ${formatTime(timeEnd + delay)}`
|
? `Event is ${millisToDelayString(delay, 'expanded')}. New schedule ${formatTime(delayedStart)} → ${formatTime(delayedEnd)}`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+25
-2
@@ -1,10 +1,33 @@
|
|||||||
|
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||||
|
|
||||||
import { formatDelay } from '../rundownEvent.utils';
|
import { formatDelay } from '../rundownEvent.utils';
|
||||||
|
|
||||||
describe('formatDelay()', () => {
|
describe('formatDelay()', () => {
|
||||||
it('adds a given delay to the start time', () => {
|
it('adds a given delay to the start time', () => {
|
||||||
const timeStart = 60000; // 1 min
|
const timeStart = 1 * MILLIS_PER_MINUTE; // 00:01
|
||||||
const delay = 60000; // 1 min
|
const delay = 1 * MILLIS_PER_MINUTE; // 00:01
|
||||||
const result = formatDelay(timeStart, delay);
|
const result = formatDelay(timeStart, delay);
|
||||||
expect(result).toEqual('New start 00:02');
|
expect(result).toEqual('New start 00:02');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('wraps negative delayed starts under midnight', () => {
|
||||||
|
const timeStart = 1 * MILLIS_PER_MINUTE; // 00:01
|
||||||
|
const delay = -2 * MILLIS_PER_MINUTE; // -00:02
|
||||||
|
const result = formatDelay(timeStart, delay);
|
||||||
|
expect(result).toEqual('New start 23:59');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wraps later-day negative delays using delay as the source of truth', () => {
|
||||||
|
const timeStart = 1 * MILLIS_PER_HOUR; // 01:00
|
||||||
|
const delay = -(1 * MILLIS_PER_HOUR + 30 * MILLIS_PER_MINUTE); // -01:30
|
||||||
|
const result = formatDelay(timeStart, delay);
|
||||||
|
expect(result).toEqual('New start 23:30');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays positive delays as wall-clock time', () => {
|
||||||
|
const timeStart = 1 * MILLIS_PER_HOUR; // 01:00
|
||||||
|
const delay = 1 * MILLIS_PER_HOUR + 30 * MILLIS_PER_MINUTE; // 01:30
|
||||||
|
const result = formatDelay(timeStart, delay);
|
||||||
|
expect(result).toEqual('New start 02:30');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
import { millisToString, removeTrailingZero } from 'ontime-utils';
|
import { millisToString, removeTrailingZero } from 'ontime-utils';
|
||||||
|
|
||||||
import { formatDuration } from '../../../common/utils/time';
|
import { formatDuration, normaliseWallClock } from '../../../common/utils/time';
|
||||||
|
|
||||||
export function formatDelay(timeStart: number, delay: number): string | undefined {
|
export function formatDelay(timeStart: number, delay: number): string | undefined {
|
||||||
if (!delay) return;
|
if (!delay) return;
|
||||||
|
|
||||||
const delayedStart = Math.max(0, timeStart + delay);
|
const delayedStart = normaliseWallClock(timeStart + delay);
|
||||||
|
|
||||||
const timeTag = removeTrailingZero(millisToString(delayedStart));
|
const timeTag = removeTrailingZero(millisToString(delayedStart));
|
||||||
return `New start ${timeTag}`;
|
return `New start ${timeTag}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatGap(gap: number, isNextDay: boolean) {
|
export function formatGap(gap: number, isNextDay: boolean) {
|
||||||
if (gap === 0) {
|
if (gap === 0) {
|
||||||
if (isNextDay) {
|
if (isNextDay) {
|
||||||
|
|||||||
Reference in New Issue
Block a user