diff --git a/src/components/TimeLine/utils.js b/src/components/TimeLine/utils.js index 3bf3de2..aff2e91 100644 --- a/src/components/TimeLine/utils.js +++ b/src/components/TimeLine/utils.js @@ -184,19 +184,30 @@ function getIconFromText(text) { return transportIcons["walk"]; } +function convertTimeToMinutes(timeString) { + // String in Teile zerlegen + const parts = timeString.split(':'); + const hours = parseInt(parts[0]); + const minutes = parseInt(parts[1]); + const seconds = parseInt(parts[2]);   + + // Berechnung der Gesamtminuten + const totalMinutes = hours * 60 + minutes + seconds / 60; + return totalMinutes; +} + export const createReturnEntries = (entries, connection, t) => { let toReturn = []; if (entries && entries.length > 0) { let _entries = entries.filter((e) => e && e.length > 0); let newStart = " "; + if (connection.totour_track_duration) { newStart = dayjs(connection.return_departure_datetime) - .subtract( - dayjs.duration(connection["fromtour_track_duration"]).asMinutes(), - "minute" - ) + .subtract(convertTimeToMinutes(connection["fromtour_track_duration"])) .format("HH:mm"); } + toReturn.push( getDepartureEntry(`${newStart} ${t("details.ankunft_bei_tourende")}`) ); @@ -248,10 +259,7 @@ export const createEntries = (entries, connection, t) => { let newStart = " "; if (connection.totour_track_duration) { newStart = dayjs(connection.connection_arrival_datetime) - .add( - dayjs.duration(connection["totour_track_duration"]).asMinutes(), - "minute" - ) + .add(convertTimeToMinutes(connection["totour_track_duration"])) .format("HH:mm"); } toReturn.push( diff --git a/src/utils/transformJson.js b/src/utils/transformJson.js index 58b62a0..da2d58f 100644 --- a/src/utils/transformJson.js +++ b/src/utils/transformJson.js @@ -1,6 +1,3 @@ -// import { useTranslation } from "i18next"; -import {formatToHHMM} from "../components/TimeLine/utils"; - function getConnectionTypeString(CT) { const connectionTypes = { @@ -73,13 +70,23 @@ export function jsonToStringArray(connection, toFrom = "to", t){ } if(toFrom === "from"){ - stringArray.unshift(` < ${t('details.std_rueckstiegsdauer_vom_touren_endpunkt', {from_tour_track_duration: formatToHHMM(connection.fromtour_track_duration)})}`) + stringArray.unshift(` < ${t('details.std_rueckstiegsdauer_vom_touren_endpunkt', {from_tour_track_duration: convertTimeToHHMM(connection.fromtour_track_duration)})}`) }else if(toFrom === "to"){ - stringArray.push(` > ${t('details.std_zustiegsdauer_zum_touren_ausgangspunkt', {totour_track_duration : formatToHHMM(connection.totour_track_duration) })}`) + stringArray.push(` > ${t('details.std_zustiegsdauer_zum_touren_ausgangspunkt', {totour_track_duration : convertTimeToHHMM(connection.totour_track_duration) })}`) } } - return stringArray; - - + return stringArray; } + +function convertTimeToHHMM(timeString) { + // String in Teile zerlegen + const parts = timeString.split(':'); + const hours = parseInt(parts[0]); + const minutes = parseInt(parts[1]); + + // Stunden und Minuten formatieren + const formattedTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; + + return formattedTime; +} \ No newline at end of file