Skip to content

Commit 09d66f6

Browse files
committed
fixup! front: refacto useOutputData
1 parent 6604760 commit 09d66f6

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

front/src/modules/timesStops/helpers/arrivalTime.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/prefer-default-export */
2-
import { dateToHHMM } from 'utils/date';
2+
import { dateToHHMMSS } from 'utils/date';
33
import { ISO8601Duration2sec, calculateTimeDifferenceInDays } from 'utils/timeManipulation';
44

55
import type { ScheduleEntry, TimeExtraDays } from '../types';
@@ -14,7 +14,7 @@ const computeDayTimeFromStartTime = (
1414
const isAfterMidnight = arrivalDatetime.getDate() !== previousDatetime.getDate();
1515

1616
const timeExtraDay = {
17-
time: dateToHHMM(arrivalDatetime, { withSeconds: true }),
17+
time: dateToHHMMSS(arrivalDatetime),
1818
daySinceDeparture: calculateTimeDifferenceInDays(startDatetime, arrivalDatetime),
1919
dayDisplayed: isAfterMidnight,
2020
};

front/src/modules/timesStops/helpers/scheduleData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dateToHHMM } from 'utils/date';
1+
import { dateToHHMMSS } from 'utils/date';
22
import { ISO8601Duration2sec } from 'utils/timeManipulation';
33

44
import type { ScheduleEntry } from '../types';
@@ -21,7 +21,7 @@ export const formatSchedule = (arrivalTime: Date, schedule?: ScheduleEntry) => {
2121
stopFor: stopForSeconds !== null ? `${stopForSeconds}` : null,
2222
...receptionSignalToSignalBooleans(schedule.reception_signal),
2323
calculatedDeparture: stopForSeconds
24-
? dateToHHMM(new Date(arrivalTime.getTime() + stopForSeconds * 1000), { withSeconds: true })
24+
? dateToHHMMSS(new Date(arrivalTime.getTime() + stopForSeconds * 1000))
2525
: undefined,
2626
};
2727
};

front/src/modules/timesStops/hooks/useOutputTableData.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
import type { PathfindingResultSuccess, TrainScheduleResult } from 'common/api/osrdEditoastApi';
1111
import { interpolateValue } from 'modules/simulationResult/SimulationResultExport/utils';
1212
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
13-
import { dateToHHMM } from 'utils/date';
13+
import { dateToHHMMSS } from 'utils/date';
1414
import { calculateTimeDifferenceInSeconds } from 'utils/timeManipulation';
1515

1616
import { ARRIVAL_TIME_ACCEPTABLE_ERROR_MS } from '../consts';
@@ -82,9 +82,7 @@ const useOutputTableData = (
8282
theoreticalMarginSeconds,
8383
calculatedMargin,
8484
diffMargins,
85-
calculatedArrival: dateToHHMM(isOnTime ? theoriticalArrival! : computedArrival, {
86-
withSeconds: true,
87-
}),
85+
calculatedArrival: dateToHHMMSS(isOnTime ? theoriticalArrival! : computedArrival),
8886
calculatedDeparture,
8987
positionOnPath: path.path_item_positions[index],
9088
};
@@ -123,7 +121,7 @@ const useOutputTableData = (
123121
opId: op.id,
124122
name: op.extensions?.identifier?.name,
125123
ch: op.extensions?.sncf?.ch,
126-
calculatedArrival: dateToHHMM(calculatedArrival, { withSeconds: true }),
124+
calculatedArrival: dateToHHMMSS(calculatedArrival),
127125
};
128126
});
129127
}, [operationalPoints, pathStepRows, simulatedTrain, startDatetime]);

front/src/utils/date.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const formatTimeDifference = (_start: number | Date, _end: number | Date)
249249
return parts.join(' ');
250250
}
251251

252-
export const dateToHHMM = (date: Date, { withSeconds } = { withSeconds: false }) => {
252+
export const dateToHHMMSS = (date: Date, { withSeconds } = { withSeconds: true }) => {
253253
const format = withSeconds ? 'HH:mm:ss' : 'HH:mm';
254254
return dayjs(date).local().format(format);
255255
};

0 commit comments

Comments
 (0)