-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathscheduleData.ts
34 lines (29 loc) · 1.03 KB
/
scheduleData.ts
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
// eslint-disable import/prefer-default-export
import { dateToHHMMSS } from 'utils/date';
import { ISO8601Duration2sec } from 'utils/timeManipulation';
import type { ScheduleEntry } from '../types';
import { receptionSignalToSignalBooleans } from './utils';
/** Format the stopFor, calculatedDeparture, shortSlipDistance and onStopSignal properties */
export const formatSchedule = (arrivalTime: Date, schedule?: ScheduleEntry) => {
if (!schedule) {
return {
stopFor: '',
calculatedDeparture: undefined,
shortSlipDistance: false,
onStopSignal: false,
};
}
if (!schedule.stop_for) {
return {
stopFor: '',
calculatedDeparture: undefined,
...receptionSignalToSignalBooleans(schedule.reception_signal),
};
}
const stopForSeconds = ISO8601Duration2sec(schedule.stop_for);
return {
stopFor: `${stopForSeconds}`,
calculatedDeparture: dateToHHMMSS(new Date(arrivalTime.getTime() + stopForSeconds * 1000)),
...receptionSignalToSignalBooleans(schedule.reception_signal),
};
};