fix: issue where a end time can be overflowing (#761)

This commit is contained in:
Carlos Valente
2024-02-06 11:42:28 +01:00
committed by GitHub
parent 965a7092d9
commit 467b595375
10 changed files with 94 additions and 13 deletions
@@ -1,7 +1,7 @@
import { memo } from 'react';
import { Select, Switch } from '@chakra-ui/react';
import { EndAction, OntimeEvent, TimerType } from 'ontime-types';
import { calculateDuration, millisToString } from 'ontime-utils';
import { calculateDuration, dayInMs, millisToString } from 'ontime-utils';
import TimeInput from '../../../common/components/input/time-input/TimeInput';
import { useEventAction } from '../../../common/hooks/useEventAction';
@@ -28,14 +28,13 @@ const EventEditorTimes = (props: EventEditorTimesProps) => {
const { eventId, timeStart, timeEnd, duration, delay, isPublic, endAction, timerType } = props;
const { updateEvent } = useEventAction();
const handleSubmit = (field: TimeActions, value: number | string | boolean) => {
const newEventData: Partial<OntimeEvent> = { id: eventId };
switch (field) {
case 'durationOverride': {
// duration defines timeEnd
newEventData.duration = value as number;
newEventData.timeEnd = timeStart + (value as number);
newEventData.timeEnd = timeStart + ((value as number) % dayInMs);
break;
}
case 'timeStart': {
@@ -1,6 +1,6 @@
import { memo } from 'react';
import { OntimeEvent } from 'ontime-types';
import { calculateDuration, millisToString } from 'ontime-utils';
import { calculateDuration, dayInMs, millisToString } from 'ontime-utils';
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
import { useEventAction } from '../../../../common/hooks/useEventAction';
@@ -29,7 +29,7 @@ const EventBlockTimers = (props: EventBlockTimerProps) => {
case 'durationOverride': {
// duration defines timeEnd
newEventData.duration = value;
newEventData.timeEnd = timeStart + value;
newEventData.timeEnd = timeStart + ((value as number) % dayInMs);
break;
}
case 'timeStart': {