From c2ef063b4b891a337557a7726cb922583f946792 Mon Sep 17 00:00:00 2001 From: Valentin Chanas Date: Tue, 3 Sep 2024 22:09:46 +0200 Subject: [PATCH] save --- front/public/locales/en/timesStops.json | 1 + front/public/locales/fr/timesStops.json | 1 + front/src/modules/timesStops/ReadOnlyTime.tsx | 6 ++- front/src/modules/timesStops/TimeInput.tsx | 7 +++- .../helpers/__tests__/scheduleData.spec.ts | 37 +------------------ .../timesStops/helpers/scheduleData.ts | 23 +++--------- front/src/modules/timesStops/helpers/utils.ts | 2 +- .../timesStops/hooks/useOutputTableData.ts | 3 +- 8 files changed, 23 insertions(+), 57 deletions(-) diff --git a/front/public/locales/en/timesStops.json b/front/public/locales/en/timesStops.json index 8071ee03bb0..23077423ac1 100644 --- a/front/public/locales/en/timesStops.json +++ b/front/public/locales/en/timesStops.json @@ -2,6 +2,7 @@ "arrivalTime": "Requested arrival Time", "calculatedArrivalTime": "Calculated arrival time", "calculatedDepartureTime": "Calculated departure time", + "d+": "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 cada441413f..d61a4da2dd4 100644 --- a/front/public/locales/fr/timesStops.json +++ b/front/public/locales/fr/timesStops.json @@ -2,6 +2,7 @@ "arrivalTime": "Arrivée demandée", "calculatedArrivalTime": "Arrivée calculée", "calculatedDepartureTime": "Départ calculé", + "d+": "J+", "departureTime": "Départ demandé", "diffMargins": "Diff. marges", "name": "Nom", diff --git a/front/src/modules/timesStops/ReadOnlyTime.tsx b/front/src/modules/timesStops/ReadOnlyTime.tsx index 350cb56c818..8980f6efe46 100644 --- a/front/src/modules/timesStops/ReadOnlyTime.tsx +++ b/front/src/modules/timesStops/ReadOnlyTime.tsx @@ -1,16 +1,20 @@ import React from 'react'; import type { CellProps } from 'react-datasheet-grid/dist/types'; +import { useTranslation } from 'react-i18next'; import type { TimeExtraDays } from './types'; type ReadOnlyTimeProps = CellProps; const ReadOnlyTime = ({ rowData }: ReadOnlyTimeProps) => { + const { t } = useTranslation('timesStops'); const { time, daySinceDeparture, dayDisplayed } = rowData || {}; if (time) { const fullString = - daySinceDeparture !== undefined && dayDisplayed ? `${time} J+${daySinceDeparture}` : time; + daySinceDeparture !== undefined && dayDisplayed + ? `${time} ${t('d+')}${daySinceDeparture}` + : time; return
{fullString}
; } return null; diff --git a/front/src/modules/timesStops/TimeInput.tsx b/front/src/modules/timesStops/TimeInput.tsx index 23bc6868f58..c1a628afda5 100644 --- a/front/src/modules/timesStops/TimeInput.tsx +++ b/front/src/modules/timesStops/TimeInput.tsx @@ -1,12 +1,14 @@ import React, { useRef, useState, useEffect } from 'react'; import type { CellProps } from 'react-datasheet-grid/dist/types'; +import { useTranslation } from 'react-i18next'; import type { TimeExtraDays } from './types'; type TimeInputProps = CellProps; const TimeInput = ({ focus, rowData, active, setRowData }: TimeInputProps) => { + const { t } = useTranslation('timesStops'); const ref = useRef(null); const [tempTimeValue, setTempTimeValue] = useState(rowData); @@ -53,7 +55,10 @@ const TimeInput = ({ focus, rowData, active, setRowData }: TimeInputProps) => { return (
{input} - J+{tempTimeValue.daySinceDeparture} + + {t('d+')} + {tempTimeValue.daySinceDeparture} +
); } diff --git a/front/src/modules/timesStops/helpers/__tests__/scheduleData.spec.ts b/front/src/modules/timesStops/helpers/__tests__/scheduleData.spec.ts index e9bb07b2553..494cd060f62 100644 --- a/front/src/modules/timesStops/helpers/__tests__/scheduleData.spec.ts +++ b/front/src/modules/timesStops/helpers/__tests__/scheduleData.spec.ts @@ -12,47 +12,12 @@ describe('computeScheduleData', () => { on_stop_signal: false, locked: false, }; - const startTime = '2024-05-14T00:00:00Z'; - expect(computeScheduleData(schedule, startTime)).toEqual({ + expect(computeScheduleData(schedule)).toEqual({ arrival: 3600, departure: 3700, stopFor: 100, }); }); - it('should compute simple arrival time in the correct timezone 2', () => { - const schedule = { - at: 'id325', - arrival: 'PT3600S', - stop_for: 'PT100S', - on_stop_signal: false, - locked: false, - }; - const startTime = '2024-05-14T01:00:00Z'; - - expect(computeScheduleData(schedule, startTime)).toEqual({ - arrival: 7200, - departure: 7300, - stopFor: 100, - }); - }); - }); - describe('after midnight', () => { - it('should compute simple arrival time in the correct timezone', () => { - const schedule = { - at: 'id325', - arrival: 'PT3600S', - stop_for: 'PT100S', - on_stop_signal: false, - locked: false, - }; - const startTime = '2024-05-14T23:50:00Z'; - - expect(computeScheduleData(schedule, startTime)).toEqual({ - arrival: 3000, - departure: 3100, - stopFor: 100, - }); - }); }); }); diff --git a/front/src/modules/timesStops/helpers/scheduleData.ts b/front/src/modules/timesStops/helpers/scheduleData.ts index c542419df5c..b3077ae4ef3 100644 --- a/front/src/modules/timesStops/helpers/scheduleData.ts +++ b/front/src/modules/timesStops/helpers/scheduleData.ts @@ -1,10 +1,5 @@ import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; -import { - ISO8601Duration2sec, - SECONDS_IN_A_DAY, - datetime2sec, - formatDurationAsISO8601, -} from 'utils/timeManipulation'; +import { ISO8601Duration2sec, formatDurationAsISO8601 } from 'utils/timeManipulation'; import type { ComputedScheduleEntry, ScheduleEntry } from '../types'; @@ -13,24 +8,18 @@ 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, startTime: string) { +export function computeScheduleData(schedule: ScheduleEntry) { if (!schedule) { return { arrival: null, departure: null, stopFor: null }; } - const startTimeSeconds = datetime2sec(new Date(startTime)); - // relative value, number of seconds since startTime - const arrivalSeconds = schedule.arrival - ? (startTimeSeconds + ISO8601Duration2sec(schedule.arrival)) % SECONDS_IN_A_DAY - : null; - + const arrivalSeconds = schedule.arrival ? ISO8601Duration2sec(schedule.arrival) : null; const stopForSeconds = schedule.stop_for ? ISO8601Duration2sec(schedule.stop_for) : null; + const departureSeconds = + arrivalSeconds && stopForSeconds ? arrivalSeconds + stopForSeconds : null; - const departure = - arrivalSeconds && stopForSeconds ? (arrivalSeconds + stopForSeconds) % SECONDS_IN_A_DAY : null; - console.log(schedule, startTime, arrivalSeconds, departure, stopForSeconds); return { arrival: arrivalSeconds, - departure, + departure: departureSeconds, stopFor: stopForSeconds, }; } diff --git a/front/src/modules/timesStops/helpers/utils.ts b/front/src/modules/timesStops/helpers/utils.ts index 2ef20f08b59..7611161c639 100644 --- a/front/src/modules/timesStops/helpers/utils.ts +++ b/front/src/modules/timesStops/helpers/utils.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-use-before-define */ import dayjs from 'dayjs'; import type { TFunction } from 'i18next'; import { round, isEqual } from 'lodash'; @@ -34,7 +35,6 @@ export const formatSuggestedViasToRowVias = ( startTime?: IsoDateTimeString, tableType?: TableType ): PathWaypointRow[] => { - console.log(operationalPoints); const formattedOps = [...operationalPoints]; // If the origin is in the ops and isn't the first operational point, we need diff --git a/front/src/modules/timesStops/hooks/useOutputTableData.ts b/front/src/modules/timesStops/hooks/useOutputTableData.ts index 84756f4517e..84b6d86dae1 100644 --- a/front/src/modules/timesStops/hooks/useOutputTableData.ts +++ b/front/src/modules/timesStops/hooks/useOutputTableData.ts @@ -82,7 +82,8 @@ function useOutputTableData( if (pathStepKey in pathStepsByUic) { const pathStepId = pathStepsByUic[pathStepKey].id || ''; const schedule = scheduleByAt[pathStepId]; - const scheduleData = computeScheduleData(schedule, selectedTrainSchedule.start_time); + // in SuggestedOP arrival and departure are the number of seconds since departure + const scheduleData = computeScheduleData(schedule); const formattedScheduleData = formatScheduleData(scheduleData); const marginsData = nextOpPoint ? computeMargins(