forked from hasadna/open-bus-map-search
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgapsService.ts
More file actions
39 lines (36 loc) · 1005 Bytes
/
Copy pathgapsService.ts
File metadata and controls
39 lines (36 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import dayjs from 'src/dayjs'
import { USER_CASE_API } from './apiConfig'
export type Gap = {
plannedStartTime?: dayjs.Dayjs
actualStartTime?: dayjs.Dayjs
gtfsRideId?: number
}
export function parseTime(time?: dayjs.ConfigType) {
if (!time) return undefined
const utcDayjs = dayjs.utc(time).utcOffset(-0.001, true).tz('Asia/Jerusalem')
if (!utcDayjs.isValid()) return undefined
return utcDayjs
}
export const getGapsAsync = (
fromTimestamp: number,
toTimestamp: number,
operatorId: string,
lineRef: number,
limit = 10000,
) => {
return USER_CASE_API.ridesExecutionListGet({
dateFrom: new Date(fromTimestamp),
dateTo: new Date(toTimestamp),
limit,
lineRef,
operatorRef: operatorId ? parseInt(operatorId) : undefined,
}).then((gaps) =>
gaps.map((gap) => {
return {
actualStartTime: parseTime(gap.actualStartTime),
plannedStartTime: parseTime(gap.plannedStartTime),
gtfsRideId: gap.gtfsRideId,
} as Gap
}),
)
}