From fda9f8e6c3ae486705a1b5d3484a02f90e9d11ee Mon Sep 17 00:00:00 2001 From: Valentin Chanas Date: Wed, 11 Sep 2024 10:51:26 +0200 Subject: [PATCH] fix fixe fixes a --- front/public/locales/en/timesStops.json | 2 +- front/public/locales/fr/timesStops.json | 2 +- .../hooks/useSetupItineraryForTrainUpdate.ts | 2 +- front/src/common/types.ts | 12 +-- front/src/modules/timesStops/ReadOnlyTime.tsx | 20 ++-- front/src/modules/timesStops/TimeInput.tsx | 11 ++- front/src/modules/timesStops/TimesStops.tsx | 19 ++-- .../modules/timesStops/TimesStopsInput.tsx | 1 + .../modules/timesStops/TimesStopsOutput.tsx | 2 +- .../helpers/__tests__/utils.spec.ts | 94 +++++++++++++++++-- .../timesStops/helpers/computeMargins.ts | 10 +- .../timesStops/helpers/scheduleData.ts | 10 +- front/src/modules/timesStops/helpers/utils.ts | 52 +++++----- .../modules/timesStops/styles/_timeInput.scss | 5 + front/src/modules/timesStops/types.ts | 7 +- .../helpers/__tests__/formatSchedule.spec.ts | 8 +- front/src/reducers/osrdconf/helpers.ts | 6 +- front/src/utils/timeManipulation.ts | 6 +- 18 files changed, 187 insertions(+), 82 deletions(-) diff --git a/front/public/locales/en/timesStops.json b/front/public/locales/en/timesStops.json index 23077423ac1..392fbcb6a94 100644 --- a/front/public/locales/en/timesStops.json +++ b/front/public/locales/en/timesStops.json @@ -2,7 +2,7 @@ "arrivalTime": "Requested arrival Time", "calculatedArrivalTime": "Calculated arrival time", "calculatedDepartureTime": "Calculated departure time", - "d+": "D+", + "dayCounter": "D+", "departureTime": "Requested departure Time", "diffMargins": "Margins diff.", "name": "Name", diff --git a/front/public/locales/fr/timesStops.json b/front/public/locales/fr/timesStops.json index d61a4da2dd4..695e5f01b47 100644 --- a/front/public/locales/fr/timesStops.json +++ b/front/public/locales/fr/timesStops.json @@ -2,7 +2,7 @@ "arrivalTime": "Arrivée demandée", "calculatedArrivalTime": "Arrivée calculée", "calculatedDepartureTime": "Départ calculé", - "d+": "J+", + "dayCounter": "J+", "departureTime": "Départ demandé", "diffMargins": "Diff. marges", "name": "Nom", diff --git a/front/src/applications/operationalStudies/hooks/useSetupItineraryForTrainUpdate.ts b/front/src/applications/operationalStudies/hooks/useSetupItineraryForTrainUpdate.ts index 353bf1a07c1..8cc1d3150bf 100644 --- a/front/src/applications/operationalStudies/hooks/useSetupItineraryForTrainUpdate.ts +++ b/front/src/applications/operationalStudies/hooks/useSetupItineraryForTrainUpdate.ts @@ -69,7 +69,7 @@ const computeBasePathSteps = (trainSchedule: TrainScheduleResult) => ...stepWithoutSecondaryCode, ch: 'secondary_code' in step ? step.secondary_code : undefined, name, - arrival, + arrival, // ISODurationString stopFor: stopFor ? ISO8601Duration2sec(stopFor).toString() : stopFor, locked, onStopSignal, diff --git a/front/src/common/types.ts b/front/src/common/types.ts index 5b83537346f..324eb16c683 100644 --- a/front/src/common/types.ts +++ b/front/src/common/types.ts @@ -24,14 +24,14 @@ export type TimeString = string; */ export type IsoDateTimeString = string; -export type RangedValue = { - begin: number; - end: number; - value: string; -}; - /** * A ISO 8601 duration string * @example "PT3600S" */ export type IsoDurationString = string; + +export type RangedValue = { + begin: number; + end: number; + value: string; +}; diff --git a/front/src/modules/timesStops/ReadOnlyTime.tsx b/front/src/modules/timesStops/ReadOnlyTime.tsx index ef8b1814d55..def2d42efb9 100644 --- a/front/src/modules/timesStops/ReadOnlyTime.tsx +++ b/front/src/modules/timesStops/ReadOnlyTime.tsx @@ -5,21 +5,19 @@ import { NO_BREAK_SPACE } from 'utils/strings'; import type { TimeExtraDays } from './types'; -type ReadOnlyTimeProps = CellProps; +type ReadOnlyTimeProps = CellProps; const ReadOnlyTime = ({ rowData }: ReadOnlyTimeProps) => { - const { t } = useTranslation('timesStops'); const { time, daySinceDeparture, dayDisplayed } = rowData || {}; - if (time) { - const fullString = - daySinceDeparture !== undefined && dayDisplayed - ? `${time}${NO_BREAK_SPACE}${t('d+')}${daySinceDeparture}` - : time; - return
{fullString}
; + if (!time) { + return null; } - return null; + const { t } = useTranslation('timesStops'); + const fullString = + daySinceDeparture !== undefined && dayDisplayed + ? `${time}${NO_BREAK_SPACE}${t('dayCounter')}${daySinceDeparture}` + : time; + return
{fullString}
; }; -ReadOnlyTime.displayName = 'ReadOnlyTime'; - export default ReadOnlyTime; diff --git a/front/src/modules/timesStops/TimeInput.tsx b/front/src/modules/timesStops/TimeInput.tsx index 4479641ffa7..59c573c47cd 100644 --- a/front/src/modules/timesStops/TimeInput.tsx +++ b/front/src/modules/timesStops/TimeInput.tsx @@ -1,5 +1,6 @@ import { useRef, useState, useEffect } from 'react'; +import cx from 'classnames'; import type { CellProps } from 'react-datasheet-grid/dist/types'; import { useTranslation } from 'react-i18next'; @@ -55,8 +56,12 @@ const TimeInput = ({ focus, rowData, active, setRowData }: TimeInputProps) => { return (
{input} - - {t('d+')} + + {t('dayCounter')} {tempTimeValue.daySinceDeparture}
@@ -65,6 +70,4 @@ const TimeInput = ({ focus, rowData, active, setRowData }: TimeInputProps) => { return input; }; -TimeInput.displayName = 'TimeInput'; - export default TimeInput; diff --git a/front/src/modules/timesStops/TimesStops.tsx b/front/src/modules/timesStops/TimesStops.tsx index b98ca090c48..66f7faad3f2 100644 --- a/front/src/modules/timesStops/TimesStops.tsx +++ b/front/src/modules/timesStops/TimesStops.tsx @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react'; import cx from 'classnames'; -import { omit } from 'lodash'; +import { isEqual } from 'lodash'; import { DynamicDataSheetGrid, type DataSheetGridProps } from 'react-datasheet-grid'; import { useTranslation } from 'react-i18next'; @@ -92,17 +92,18 @@ const TimesStops = ({ ); updatedRows = updateDaySinceDeparture(updatedRows, startTime); if (!updatedRows[op.fromRowIndex].isMarginValid) { + newRows[op.fromRowIndex].isMarginValid = false; setRows(newRows); } else { const newVias = updatedRows - .filter((row) => row.arrival) - .map((row) => { - const arrival = durationSinceStartTime(startTime, row.arrival); - return { - ...omit(row, 'departure'), - arrival, - }; - }); + .filter((row, index) => !isEqual(row, rows[index])) + .map( + (row) => + ({ + ...row, + ...(row.arrival && { arrival: durationSinceStartTime(startTime, row.arrival) }), + }) as SuggestedOP + ); dispatch(upsertSeveralViasFromSuggestedOP(newVias)); } }} diff --git a/front/src/modules/timesStops/TimesStopsInput.tsx b/front/src/modules/timesStops/TimesStopsInput.tsx index 2560c90b0c2..840d43fa2a1 100644 --- a/front/src/modules/timesStops/TimesStopsInput.tsx +++ b/front/src/modules/timesStops/TimesStopsInput.tsx @@ -40,6 +40,7 @@ type TimesStopsInputProps = { startTime: string; pathSteps: PathStep[]; }; + const TimesStopsinput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInputProps) => { const dispatch = useAppDispatch(); const { updatePathSteps } = useOsrdConfActions(); diff --git a/front/src/modules/timesStops/TimesStopsOutput.tsx b/front/src/modules/timesStops/TimesStopsOutput.tsx index cb358efeaaf..3048e40ba72 100644 --- a/front/src/modules/timesStops/TimesStopsOutput.tsx +++ b/front/src/modules/timesStops/TimesStopsOutput.tsx @@ -53,7 +53,7 @@ const TimesStopsOutput = ({ tableType={TableType.Output} cellClassName={({ rowData: rowData_ }) => { const rowData = rowData_ as PathWaypointRow; - const arrivalScheduleNotRespected = rowData?.arrival?.time + const arrivalScheduleNotRespected = rowData.arrival?.time ? rowData.calculatedArrival !== rowData.arrival.time : false; const negativeDiffMargins = Number(rowData.diffMargins?.split(NO_BREAK_SPACE)[0]) < 0; diff --git a/front/src/modules/timesStops/helpers/__tests__/utils.spec.ts b/front/src/modules/timesStops/helpers/__tests__/utils.spec.ts index 4630e425421..662d41e32d6 100644 --- a/front/src/modules/timesStops/helpers/__tests__/utils.spec.ts +++ b/front/src/modules/timesStops/helpers/__tests__/utils.spec.ts @@ -39,7 +39,7 @@ describe('updateRowTimesAndMargin', () => { }); }); }); - describe('theoritical margin is incorrect', () => { + describe('theoretical margin is incorrect', () => { it('should set isMarginValid flag to false', () => { const rowData = { opId: 'd94a2af4', @@ -54,8 +54,8 @@ describe('updateRowTimesAndMargin', () => { expect(result.isMarginValid).toBe(false); }); }); - describe('user removed first row theoritical margin', () => { - it('should set the theoritical margin back to 0%', () => { + describe('user removed first row theoretical margin', () => { + it('should set the theoretical margin back to 0%', () => { const rowData = { opId: 'd94a2af4', name: 'Gr', @@ -106,9 +106,91 @@ describe('updateRowTimesAndMargin', () => { }); }); }); + describe('arrival, departure & stopFor are set, arrival gets erased', () => { + it('should keep stopFor and remove departure', () => { + const rowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: undefined, + departure: { time: '00:20:00' }, + stopFor: '600', + } as PathWaypointRow; + const previousRowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: { time: '00:10:00' }, + departure: { time: '00:20:00' }, + stopFor: '600', + } as PathWaypointRow; + const result = updateRowTimesAndMargin(rowData, previousRowData, whateverOperation, 4); + expect(result).toEqual({ + opId: 'd94a2af4', + name: 'Gr', + arrival: undefined, + departure: undefined, + stopFor: '600', + isMarginValid: true, + }); + }); + }); + describe('arrival, departure & stopFor are set, departure gets erased', () => { + it('should keep arrival and remove stopFor', () => { + const rowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: { time: '00:10:00' }, + departure: undefined, + stopFor: '600', + } as PathWaypointRow; + const previousRowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: { time: '00:10:00' }, + departure: { time: '00:20:00' }, + stopFor: '600', + } as PathWaypointRow; + const result = updateRowTimesAndMargin(rowData, previousRowData, whateverOperation, 4); + expect(result).toEqual({ + opId: 'd94a2af4', + name: 'Gr', + arrival: { time: '00:10:00' }, + departure: undefined, + stopFor: undefined, + isMarginValid: true, + onStopSignal: false + }); + }); + }); + describe('stopFor only is set, departure gets added', () => { + it('should set arrival too', () => { + const rowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: undefined, + departure: { time: '00:20:00' }, + stopFor: '600', + } as PathWaypointRow; + const previousRowData = { + opId: 'd94a2af4', + name: 'Gr', + arrival: undefined, + departure: undefined, + stopFor: '600', + } as PathWaypointRow; + const result = updateRowTimesAndMargin(rowData, previousRowData, whateverOperation, 4); + expect(result).toEqual({ + opId: 'd94a2af4', + name: 'Gr', + arrival: { time: '00:10:00' }, + departure: { time: '00:20:00' }, + stopFor: '600', + isMarginValid: true, + }); + }); + }); }); -describe('updateTimeAndDays', () => { +describe('updateDaySinceDeparture', () => { describe('1 day span', () => { it('should add the day since departure', () => { const pathWaypointRows = [ @@ -479,7 +561,7 @@ describe('durationSinceStartTime', () => { describe('calculateStepTimeDays', () => { it('should return correct time and daySinceDeparture', () => { const startTime = '2023-09-01T10:00:00Z'; - const isoDuration = 'PT36000S'; + const isoDuration = 'PT36000S'; // 10 hours const result = calculateStepTimeAndDays(startTime, isoDuration); @@ -491,7 +573,7 @@ describe('calculateStepTimeDays', () => { it('should return correct time and daySinceDeparture, daySinceDeparture 1', () => { const startTime = '2023-09-01T10:00:00Z'; - const isoDuration = 'PT122400S'; + const isoDuration = 'PT122400S'; // 1 day 10 hours const result = calculateStepTimeAndDays(startTime, isoDuration); diff --git a/front/src/modules/timesStops/helpers/computeMargins.ts b/front/src/modules/timesStops/helpers/computeMargins.ts index bb0b647da4b..b1557f6ddae 100644 --- a/front/src/modules/timesStops/helpers/computeMargins.ts +++ b/front/src/modules/timesStops/helpers/computeMargins.ts @@ -14,18 +14,18 @@ function getTheoreticalMargin(selectedTrainSchedule: TrainScheduleResult, pathSt if (selectedTrainSchedule.path[0].id === pathStepId) { return selectedTrainSchedule.margins?.values[0]; } - const theoriticalMarginBoundaryIndex = selectedTrainSchedule.margins?.boundaries?.findIndex( + const theoreticalMarginBoundaryIndex = selectedTrainSchedule.margins?.boundaries?.findIndex( (id) => id === pathStepId ); if ( - theoriticalMarginBoundaryIndex === undefined || - theoriticalMarginBoundaryIndex < 0 || - theoriticalMarginBoundaryIndex > selectedTrainSchedule.margins!.values.length - 2 + theoreticalMarginBoundaryIndex === undefined || + theoreticalMarginBoundaryIndex < 0 || + theoreticalMarginBoundaryIndex > selectedTrainSchedule.margins!.values.length - 2 ) { return undefined; } - return selectedTrainSchedule.margins!.values[theoriticalMarginBoundaryIndex + 1]; + return selectedTrainSchedule.margins!.values[theoreticalMarginBoundaryIndex + 1]; } function computeDuration( diff --git a/front/src/modules/timesStops/helpers/scheduleData.ts b/front/src/modules/timesStops/helpers/scheduleData.ts index b3077ae4ef3..166bee7c41e 100644 --- a/front/src/modules/timesStops/helpers/scheduleData.ts +++ b/front/src/modules/timesStops/helpers/scheduleData.ts @@ -1,3 +1,4 @@ +import type { IsoDurationString } from 'common/types'; import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; import { ISO8601Duration2sec, formatDurationAsISO8601 } from 'utils/timeManipulation'; @@ -6,7 +7,6 @@ import type { ComputedScheduleEntry, ScheduleEntry } from '../types'; /** * * @param schedule for a given operational point - * @param startTime time of departure from the very beginning of the route */ export function computeScheduleData(schedule: ScheduleEntry) { if (!schedule) { @@ -27,8 +27,12 @@ export function computeScheduleData(schedule: ScheduleEntry) { export function formatScheduleData( scheduleData: ComputedScheduleEntry ): Pick { - const arrival = scheduleData.arrival ? formatDurationAsISO8601(scheduleData.arrival) : null; - const departure = scheduleData.departure ? formatDurationAsISO8601(scheduleData.departure) : null; + const arrival: IsoDurationString | null = scheduleData.arrival + ? formatDurationAsISO8601(scheduleData.arrival) + : null; + const departure: IsoDurationString | null = scheduleData.departure + ? formatDurationAsISO8601(scheduleData.departure) + : null; const stopFor = scheduleData.stopFor !== null ? String(scheduleData.stopFor) : ''; return { arrival, diff --git a/front/src/modules/timesStops/helpers/utils.ts b/front/src/modules/timesStops/helpers/utils.ts index 6178aa73235..5515be1cb8e 100644 --- a/front/src/modules/timesStops/helpers/utils.ts +++ b/front/src/modules/timesStops/helpers/utils.ts @@ -4,7 +4,7 @@ import type { TFunction } from 'i18next'; import { round, isEqual } from 'lodash'; import { keyColumn, createTextColumn } from 'react-datasheet-grid'; -import type { IsoDateTimeString, IsoDurationString } from 'common/types'; +import type { IsoDateTimeString, IsoDurationString, TimeString } from 'common/types'; import { matchPathStepAndOp } from 'modules/pathfinding/utils'; import type { OperationalPointWithTimeAndSpeed } from 'modules/trainschedule/components/DriverTrainSchedule/types'; import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; @@ -15,6 +15,7 @@ import { datetime2sec, durationInSeconds, formatDurationAsISO8601, + sec2time, SECONDS_IN_A_DAY, secToHoursString, time2sec, @@ -70,16 +71,18 @@ export const formatSuggestedViasToRowVias = ( const { arrival, onStopSignal, stopFor, theoreticalMargin } = objectToUse || {}; const isMarginValid = theoreticalMargin ? marginRegExValidation.test(theoreticalMargin) : true; - const roundedArrivalTime = i === 0 ? 'PT0S' : arrival; - const arrivalInSeconds = roundedArrivalTime ? time2sec(roundedArrivalTime) : null; + const durationArrivalTime = i === 0 ? 'PT0S' : arrival; + const arrivalInSeconds = durationArrivalTime ? time2sec(durationArrivalTime) : null; - const formattedArrival = calculateStepTimeAndDays(startTime, roundedArrivalTime); + const formattedArrival = calculateStepTimeAndDays(startTime, durationArrivalTime); const departureTime = stopFor && arrivalInSeconds ? secToHoursString(arrivalInSeconds + Number(stopFor), true) : undefined; - const formattedDeparture = departureTime ? { time: departureTime } : undefined; + const formattedDeparture: TimeExtraDays | undefined = departureTime + ? { time: departureTime } + : undefined; return { ...op, isMarginValid, @@ -153,17 +156,24 @@ export function updateRowTimesAndMargin( ): PathWaypointRow { const newRowData = { ...rowData }; if ( - newRowData.departure && - newRowData.arrival && - (!isEqual(newRowData.arrival, previousRowData.arrival) || - !isEqual(newRowData.departure, previousRowData.departure)) + !isEqual(newRowData.arrival, previousRowData.arrival) || + !isEqual(newRowData.departure, previousRowData.departure) ) { - newRowData.stopFor = String( - durationInSeconds( - time2sec(newRowData.arrival.time || ''), - time2sec(newRowData.departure.time || '') - ) - ); + if (newRowData.departure && newRowData.arrival) { + newRowData.stopFor = String( + durationInSeconds(time2sec(newRowData.arrival.time), time2sec(newRowData.departure.time)) + ); + } else if (newRowData.departure) { + if (!previousRowData.departure) { + newRowData.arrival = { time: sec2time(time2sec(newRowData.departure.time) - Number(newRowData.stopFor))}; + } else { + newRowData.departure = undefined; + } + } else if (newRowData.arrival && previousRowData.departure) { + // we just erased departure value + newRowData.stopFor = undefined; + + } } if (!newRowData.stopFor && op.fromRowIndex !== allWaypointsLength - 1) { newRowData.onStopSignal = false; @@ -186,11 +196,11 @@ export function updateRowTimesAndMargin( * This function goes through the whole array of path waypoints * and updates the number of days since departure. */ -export function updateDaySinceDeparture>( - pathWaypointRows: T[], +export function updateDaySinceDeparture( + pathWaypointRows: PathWaypointRow[], startTime?: IsoDateTimeString, keepFirstIndexArrival?: boolean -): T[] { +): PathWaypointRow[] { let currentDaySinceDeparture = 0; let previousTime = startTime ? datetime2sec(new Date(startTime)) : Number.NEGATIVE_INFINITY; @@ -272,9 +282,9 @@ export function calculateStepTimeAndDays( const start = dayjs(startTime); const duration = dayjs.duration(isoDuration); - const endTime = start.add(duration); - const daySinceDeparture = endTime.diff(start, 'day'); - const time = endTime.format('HH:mm:ss'); + const waypointArrivalTime = start.add(duration); + const daySinceDeparture = waypointArrivalTime.diff(start, 'day'); + const time: TimeString = waypointArrivalTime.format('HH:mm:ss'); return { time, diff --git a/front/src/modules/timesStops/styles/_timeInput.scss b/front/src/modules/timesStops/styles/_timeInput.scss index 2e241e02bcc..d5369669282 100644 --- a/front/src/modules/timesStops/styles/_timeInput.scss +++ b/front/src/modules/timesStops/styles/_timeInput.scss @@ -12,4 +12,9 @@ top: 0.075rem; pointer-events: none; } + + span.extra-text-firefox { + top: 0.03rem; + left: 6.1rem; + } } diff --git a/front/src/modules/timesStops/types.ts b/front/src/modules/timesStops/types.ts index 70c618e5f14..fb7cf1e56ab 100644 --- a/front/src/modules/timesStops/types.ts +++ b/front/src/modules/timesStops/types.ts @@ -1,17 +1,18 @@ import type { TrainScheduleBase, TrainScheduleResult } from 'common/api/osrdEditoastApi'; +import type { TimeString } from 'common/types'; import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; import type { ArrayElement } from 'utils/types'; export type TimeExtraDays = { - time: string | null | undefined; + time: TimeString; daySinceDeparture?: number; dayDisplayed?: boolean; }; export type PathWaypointRow = Omit & { isMarginValid: boolean; - arrival?: TimeExtraDays | undefined; // value asked by user - departure?: TimeExtraDays | undefined; // value asked by user + arrival?: TimeExtraDays; // value asked by user + departure?: TimeExtraDays; // value asked by user }; export enum TableType { diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts index 5d6e41287d5..bc6eba664e4 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/__tests__/formatSchedule.spec.ts @@ -7,7 +7,7 @@ import formatSchedule from '../formatSchedule'; describe('formatSchedule', () => { describe('same day', () => { it('should ignore steps without arrival or stopFor', () => { - const pathSteps = [ + const pathSteps: PathStep[] = [ { id: 'id331', deleted: false, @@ -17,12 +17,12 @@ describe('formatSchedule', () => { name: 'G', positionOnPath: 0, }, - ] as PathStep[]; + ]; const result = formatSchedule(pathSteps); expect(result?.length).toBe(0); }); it('should format the train schedule', () => { - const pathSteps = [ + const pathSteps: PathStep[] = [ { id: 'id332', deleted: false, @@ -36,7 +36,7 @@ describe('formatSchedule', () => { locked: false, onStopSignal: false, }, - ] as PathStep[]; + ]; const result = formatSchedule(pathSteps); expect(result).toEqual([ { diff --git a/front/src/reducers/osrdconf/helpers.ts b/front/src/reducers/osrdconf/helpers.ts index b815477c43d..a643ec6992b 100644 --- a/front/src/reducers/osrdconf/helpers.ts +++ b/front/src/reducers/osrdconf/helpers.ts @@ -147,13 +147,13 @@ export const updateDestinationPathStep = ( ) => updatePathStepAtIndex(pathSteps, pathSteps.length - 1, destination, replaceCompletely); /** - * modifies the array statePathSteps in place + * Modifies the array statePathSteps in place in the reducer */ export function upsertPathStep(statePathSteps: (PathStep | null)[], op: SuggestedOP) { // We know that, at this point, origin and destination are defined because pathfinding has been done const cleanPathSteps = compact(statePathSteps); - let newVia = { + let newVia: PathStep = { ...pick(op, [ 'coordinates', 'positionOnPath', @@ -174,7 +174,7 @@ export function upsertPathStep(statePathSteps: (PathStep | null)[], op: Suggeste track: op.track, offset: op.offsetOnTrack, }), - } as PathStep; + }; const stepIndex = cleanPathSteps.findIndex((step) => pathStepMatchesOp(step, op)); if (stepIndex >= 0) { diff --git a/front/src/utils/timeManipulation.ts b/front/src/utils/timeManipulation.ts index ca34e76de2e..7bfbb916f43 100644 --- a/front/src/utils/timeManipulation.ts +++ b/front/src/utils/timeManipulation.ts @@ -6,6 +6,8 @@ import type { TimeString } from 'common/types'; dayjs.extend(duration); +export const SECONDS_IN_A_DAY = 86400; + export function sec2ms(sec: number) { return sec * 1000; } @@ -53,7 +55,7 @@ export function datetime2sec(time: Date): number { } export function durationInSeconds(start: number, end: number) { - return end > start ? end - start : end + 86400 - start; + return end > start ? end - start : end + SECONDS_IN_A_DAY - start; } export function calculateTimeDifferenceInSeconds(time1: string | Date, time2: string | Date) { @@ -86,5 +88,3 @@ export function secToHoursString(sec: number | null, withSeconds = false): TimeS const format = withSeconds ? '%H:%M:%S' : '%H:%M'; return d3.utcFormat(format)(new Date(sec * 1000)); } - -export const SECONDS_IN_A_DAY = 86400;