Skip to content

Commit

Permalink
Use luxon
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Dec 6, 2023
1 parent f421da2 commit 25af9c5
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import { useTranslations } from 'next-intl';
import styles from './LinesExplorerContentPatternPathStopRealtime.module.css';
import LiveIcon from '@/components/LiveIcon/LiveIcon';
import { IconClock } from '@tabler/icons-react';
import { DateTime } from 'luxon';

/* * */

@@ -51,11 +52,11 @@ export default function LinesExplorerContentPatternPathStopRealtime({ patternId,
return Math.floor(timeDifferenceBetweenEstimateAndNow / 1000 / 60);
});
// Limit array to the max amount of items
const limitedNextEstimatedArrivals = formattedNextEstimatedArrivals.slice(0, 3);
const limitedNextEstimatedArrivals = formattedNextEstimatedArrivals.slice(0, maxEstimatedArrivals);
// Return result
return limitedNextEstimatedArrivals;
//
}, [realtimeData, patternId, stopSequence]);
}, [realtimeData, maxEstimatedArrivals, patternId, stopSequence]);

const nextScheduledArrivals = useMemo(() => {
// Return early if no data is available
@@ -79,15 +80,15 @@ export default function LinesExplorerContentPatternPathStopRealtime({ patternId,
const sortedNextScheduledArrivals = filteredNextScheduledArrivals.sort((a, b) => a.scheduled_arrival_unix - b.scheduled_arrival_unix);
// Format the arrival times
const formattedNextScheduledArrivals = sortedNextScheduledArrivals.map((item) => {
const dateObject = new Date(item.scheduled_arrival_unix * 1000);
return `${dateObject.getHours()}:${dateObject.getMinutes()}`;
const dateTimeObject = DateTime.fromSeconds(item.scheduled_arrival_unix, { zone: 'UTC' });
return `${dateTimeObject.toFormat('HH', { zone: 'Europe/Lisbon' })}:${dateTimeObject.toFormat('mm', { zone: 'Europe/Lisbon' })}`;
});
// Limit array to the max amount of items
const limitedNextScheduledArrivals = formattedNextScheduledArrivals.slice(0, 3);
const limitedNextScheduledArrivals = formattedNextScheduledArrivals.slice(0, maxScheduledArrivals);
// Return result
return limitedNextScheduledArrivals;
//
}, [realtimeData, patternId, stopSequence]);
}, [realtimeData, maxScheduledArrivals, patternId, stopSequence]);

//
// D. Render components
2 changes: 1 addition & 1 deletion frontend/components/LinesExplorerMap/LinesExplorerMap.js
Original file line number Diff line number Diff line change
@@ -214,7 +214,7 @@ export default function LinesExplorerMap() {

useEffect(() => {
// Check if map is ready
if (linesExplorerMap?.getSource('all-stops') === undefined) return;
if (linesExplorerMap && linesExplorerMap?.getSource('all-stops') === undefined) return;
// Check if auto zoom is enabled
if (!linesExplorerContext.map.auto_zoom) return;
// Check if there is a selected map feature
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -20,9 +20,10 @@
"@turf/turf": "6.5.0",
"dayjs": "1.11.10",
"inflected": "2.1.0",
"luxon": "3.4.4",
"maplibre-gl": "3.6.2",
"next": "14.0.3",
"next-intl": "3.2.2",
"next-intl": "3.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-map-gl": "7.1.6",
@@ -32,13 +33,13 @@
},
"devDependencies": {
"@types/node": "20.10.3",
"@types/react": "18.2.41",
"@types/react": "18.2.42",
"@types/react-dom": "18.2.17",
"eslint": "8.55.0",
"eslint-config-next": "14.0.3",
"postcss": "8.4.32",
"postcss-preset-mantine": "1.11.1",
"postcss-simple-vars": "7.0.1",
"typescript": "5.3.2"
"typescript": "5.3.3"
}
}

0 comments on commit 25af9c5

Please sign in to comment.