Skip to content

Commit 8a1a05a

Browse files
committed
Added utility to format stop time
1 parent cc02db7 commit 8a1a05a

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@reduxjs/toolkit": "^1.6.2",
1616
"@turf/turf": "^6.5.0",
1717
"graphql": "^16.0.1",
18+
"luxon": "^2.2.0",
1819
"react": "17.0.2",
1920
"react-native": "0.66.3",
2021
"react-native-dotenv": "^3.3.0",
@@ -30,6 +31,7 @@
3031
"@expo/config-plugins": "^4.0.11",
3132
"@react-native-community/eslint-config": "^2.0.0",
3233
"@types/jest": "^26.0.23",
34+
"@types/luxon": "^2.0.7",
3335
"@types/react-native": "^0.66.4",
3436
"@types/react-native-dotenv": "^0.2.0",
3537
"@types/react-redux": "^7.1.20",

src/components/Stop.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ const getCircleStyles = (
1717
color: string,
1818
isActive: boolean,
1919
): CircleLayerStyle => ({
20-
circleRadius: isActive ? 12 : 6,
21-
circleColor: `#${color || 'ddd'}`,
20+
circleRadius: isActive ? 16 : 6,
21+
circleColor: `#${isActive ? 'ddd' : color || 'ddd'}`,
2222
circleStrokeColor: `#ddd`,
2323
circleStrokeWidth: 2,
2424
circlePitchScale: 'map',
2525
circlePitchAlignment: 'map',
26+
circleColorTransition: {
27+
duration: 4000,
28+
delay: 4000,
29+
},
30+
circleRadiusTransition: {
31+
duration: 500,
32+
delay: 500,
33+
},
2634
});
2735

2836
const Stop: FC<Props> = ({

src/interfaces/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ export interface IShape {
5353
coordinates: Coordinate[];
5454
};
5555
}
56+
57+
export interface IInterval {
58+
hours: number;
59+
minutes: number;
60+
seconds: number;
61+
}

src/screens/trip/TripScreen.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import {
99
import { useQuery } from '@apollo/client';
1010
import { Navigation } from 'react-native-navigation';
1111
import { NavigationContext } from 'react-native-navigation-hooks';
12-
import Loading from 'components/Loading';
13-
import Error from 'components/Error';
1412
import { useAppDispatch } from 'store';
1513
import { setActiveStop } from 'slices/stops';
1614
import { setActiveTrip } from 'slices/trips';
1715
import { GET_TRIP } from 'apollo/queries';
16+
import Loading from 'components/Loading';
17+
import Error from 'components/Error';
1818
import { IRoute, ITrip, IStopTime } from 'interfaces';
19+
import { getTimeFromInterval } from 'util/';
1920
import styles from './styles';
2021

2122
type Props = {
@@ -76,17 +77,18 @@ const TripScreen: FC<Props> = ({ route }) => {
7677
}
7778
}, [nextTrip, dispatch]);
7879

79-
const renderItem = ({ item }: ListRenderItemInfo<IStopTime>) => (
80-
<TouchableOpacity style={styles.button} onPress={() => goToStop(item)}>
81-
<Text>
82-
{item.stopSequence} - {item.stop.stopId} - {item.stop.stopName}
83-
</Text>
84-
<Text>
85-
Departs at: {item.departureTime.hours}:{item.departureTime.minutes}:
86-
{item.departureTime.seconds ? item.departureTime.seconds : '00'}
87-
</Text>
88-
</TouchableOpacity>
89-
);
80+
const renderItem = ({ item }: ListRenderItemInfo<IStopTime>) => {
81+
const time = getTimeFromInterval(item.departureTime);
82+
83+
return (
84+
<TouchableOpacity style={styles.button} onPress={() => goToStop(item)}>
85+
<Text>
86+
{item.stopSequence} - {item.stop.stopId} - {item.stop.stopName}
87+
</Text>
88+
<Text>Departs at: {time}</Text>
89+
</TouchableOpacity>
90+
);
91+
};
9092

9193
const renderTrip = (trip: ITrip): React.ReactElement => {
9294
return (

src/util/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { DateTime } from 'luxon';
2+
import { IInterval } from 'interfaces';
3+
4+
const TIME_ZONE = 'America/New_York';
5+
6+
/**
7+
* Get human-readable time, 12 hour format, from interval
8+
* @param interval
9+
* @returns {string}
10+
*/
11+
export const getTimeFromInterval = (interval: IInterval): string => {
12+
const { hours: hour, minutes: minute, seconds: second } = interval;
13+
const time = DateTime.fromObject({
14+
hour,
15+
minute,
16+
second,
17+
})
18+
.setZone(TIME_ZONE)
19+
.toLocaleString(DateTime.TIME_SIMPLE);
20+
return time;
21+
};

src/util/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "util"
3+
}

0 commit comments

Comments
 (0)