mirror of
https://github.com/cpvalente/ontime.git
synced 2026-07-26 10:38:55 +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_MINUTE,
|
||||
MILLIS_PER_SECOND,
|
||||
dayInMs,
|
||||
formatFromMillis,
|
||||
getExpectedStart,
|
||||
} from 'ontime-utils';
|
||||
@@ -29,6 +30,11 @@ export function nowInMillis(): number {
|
||||
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
|
||||
* @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 { useEntryActionsContext } from '../../../../common/context/EntryActionsContext';
|
||||
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 style from '../EntryEditor.module.scss';
|
||||
@@ -68,8 +68,10 @@ function EventEditorTimes({
|
||||
};
|
||||
|
||||
const hasDelay = delay !== 0;
|
||||
const delayedStart = normaliseWallClock(timeStart + delay);
|
||||
const delayedEnd = normaliseWallClock(timeEnd + delay);
|
||||
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 (
|
||||
|
||||
+25
-2
@@ -1,10 +1,33 @@
|
||||
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE } from 'ontime-utils';
|
||||
|
||||
import { formatDelay } from '../rundownEvent.utils';
|
||||
|
||||
describe('formatDelay()', () => {
|
||||
it('adds a given delay to the start time', () => {
|
||||
const timeStart = 60000; // 1 min
|
||||
const delay = 60000; // 1 min
|
||||
const timeStart = 1 * MILLIS_PER_MINUTE; // 00:01
|
||||
const delay = 1 * MILLIS_PER_MINUTE; // 00:01
|
||||
const result = formatDelay(timeStart, delay);
|
||||
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 { formatDuration } from '../../../common/utils/time';
|
||||
import { formatDuration, normaliseWallClock } from '../../../common/utils/time';
|
||||
|
||||
export function formatDelay(timeStart: number, delay: number): string | undefined {
|
||||
if (!delay) return;
|
||||
|
||||
const delayedStart = Math.max(0, timeStart + delay);
|
||||
const delayedStart = normaliseWallClock(timeStart + delay);
|
||||
|
||||
const timeTag = removeTrailingZero(millisToString(delayedStart));
|
||||
return `New start ${timeTag}`;
|
||||
}
|
||||
|
||||
export function formatGap(gap: number, isNextDay: boolean) {
|
||||
if (gap === 0) {
|
||||
if (isNextDay) {
|
||||
|
||||
Reference in New Issue
Block a user