Skip to content

Commit

Permalink
Fix itinerary times Zustieg / Rückstieg
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheppner committed Oct 11, 2024
1 parent 9d2a5c1 commit c8f353f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
24 changes: 16 additions & 8 deletions src/components/TimeLine/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")}`)
);
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 15 additions & 8 deletions src/utils/transformJson.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import { useTranslation } from "i18next";
import {formatToHHMM} from "../components/TimeLine/utils";

function getConnectionTypeString(CT) {

const connectionTypes = {
Expand Down Expand Up @@ -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;
}

0 comments on commit c8f353f

Please sign in to comment.