Skip to content

Commit

Permalink
Added functinonality to set the correct searchTimeParam when navigati…
Browse files Browse the repository at this point in the history
…ng from detailed view back to search results. + some minor updates in the code.
  • Loading branch information
jonasbrunvoll committed Feb 26, 2024
1 parent 54146fe commit c935542
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/page-modules/assistant/client/journey-planner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { swrFetcher } from '@atb/modules/api-browser';
import useSWRInfinite from 'swr/infinite';
import { createTripQuery, tripQueryToQueryString } from '../../utils';
import { useEffect, useState } from 'react';
import { formatLocalTimeToCTE } from '@atb/utils/date';
import { formatCETToLocal } from '@atb/utils/date';

const MAX_NUMBER_OF_INITIAL_SEARCH_ATTEMPTS = 3;
const INITIAL_NUMBER_OF_WANTED_TRIP_PATTERNS = 6;
Expand Down Expand Up @@ -45,7 +45,7 @@ export function useTripPatterns(
...tripQuery,
searchTime: {
...tripQuery.searchTime,
dateTime: formatLocalTimeToCTE(tripQuery.searchTime.dateTime),
dateTime: formatCETToLocal(tripQuery.searchTime.dateTime),
},
},
);
Expand Down
5 changes: 4 additions & 1 deletion src/page-modules/assistant/details/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatLocalTimeToCET } from '@atb/utils/date';
import { parseTripQueryString } from '../server/journey-planner';

export function formatQuayName(quayName?: string, publicCode?: string | null) {
Expand Down Expand Up @@ -51,7 +52,9 @@ export function tripQueryStringToQueryParams(
const searchMode = arriveBy ? 'arriveBy' : 'departBy';
const fromLayer = from.place?.includes('StopPlace') ? 'venue' : 'address';
const toLayer = to.place?.includes('StopPlace') ? 'venue' : 'address';
const searchTime = String(new Date(originalSearchTime).getTime());
const searchTime = String(
formatLocalTimeToCET(new Date(originalSearchTime).getTime()),
);

const params = {
searchMode,
Expand Down
9 changes: 7 additions & 2 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,14 @@ export function setTimezoneIfNeeded(date: Date): Date {
return new Date(date.toLocaleString(FALLBACK_LANGUAGE, { timeZone: CET }));
}

export function formatLocalTimeToCTE(localTime: number) {
export function formatCETToLocal(localTime: number) {
const offset = getOffsetTimezone();
return 3600000 * (offset - 1) + localTime;
return localTime + 3600000 * (offset - 1);
}

export function formatLocalTimeToCET(cet: number) {
const offset = getOffsetTimezone();
return cet - 3600000 * (offset - 1);
}

function getOffsetTimezone() {
Expand Down

0 comments on commit c935542

Please sign in to comment.