newStaffLDB-API #48
2749
package-lock.json
generated
2749
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@
|
||||
"zlib": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@owlboard/ts-types": "^0.0.8",
|
||||
"@owlboard/ts-types": "^0.0.9",
|
||||
"@types/jest": "^29.5.3",
|
||||
"eslint": "^8.39.0",
|
||||
"jest": "^29.6.2",
|
||||
|
@ -74,6 +74,7 @@ function transformTrainServices(input: any): TrainServices[] {
|
||||
services = [input.service];
|
||||
}
|
||||
for (const service of services) {
|
||||
const times = parseTimes(service)
|
||||
const trainService: TrainServices = {
|
||||
rid: service?.rid,
|
||||
uid: service?.uid,
|
||||
@ -90,12 +91,12 @@ function transformTrainServices(input: any): TrainServices[] {
|
||||
delayReason: service?.delayReason,
|
||||
arrivalType: service?.arrivalType,
|
||||
departureType: service?.departureType,
|
||||
sta: transformUnspecifiedDateTime(service?.sta),
|
||||
eta: transformUnspecifiedDateTime(service?.eta),
|
||||
ata: transformUnspecifiedDateTime(service?.ata),
|
||||
std: transformUnspecifiedDateTime(service?.std),
|
||||
etd: transformUnspecifiedDateTime(service?.etd),
|
||||
atd: transformUnspecifiedDateTime(service?.atd),
|
||||
sta: times.sta,
|
||||
eta: times.eta,
|
||||
ata: times.ata,
|
||||
std: times.std,
|
||||
etd: times.etd,
|
||||
atd: times.atd,
|
||||
};
|
||||
Object.keys(trainService).forEach(
|
||||
(key) => trainService[key] === undefined && delete trainService[key]
|
||||
@ -146,3 +147,41 @@ function transformUnspecifiedDateTime(input: string): Date | undefined {
|
||||
const date = tz(input, "Europe/London");
|
||||
return date.toDate();
|
||||
}
|
||||
|
||||
function parseTimes(service: TrainServices) {
|
||||
let {sta, eta, ata, std, etd, atd} = Object.fromEntries(
|
||||
Object.entries(service).map(([key, value]) => [key, transformUnspecifiedDateTime(value)])
|
||||
)
|
||||
|
||||
let etaResult: Date | undefined | string = eta;
|
||||
let ataResult: Date | undefined | string = ata;
|
||||
let etdResult: Date | undefined | string = etd;
|
||||
let atdResult: Date | undefined | string = atd;
|
||||
|
||||
if (sta) {
|
||||
if (eta !== undefined && Math.abs(eta.getTime() - sta.getTime()) / 60000 <= 1.5) {
|
||||
etaResult = "RT";
|
||||
}
|
||||
if (ata !== undefined && Math.abs(ata.getTime() - sta.getTime()) / 60000 <= 1.5) {
|
||||
ataResult = "RT";
|
||||
}
|
||||
}
|
||||
|
||||
if (std) {
|
||||
if (etd !== undefined && Math.abs(etd.getTime() - std.getTime()) / 60000 <= 1.5) {
|
||||
etdResult = "RT";
|
||||
}
|
||||
if (atd !== undefined && Math.abs(atd.getTime() - std.getTime()) / 60000 <= 1.5) {
|
||||
atdResult = "RT";
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
sta: sta,
|
||||
eta: etaResult,
|
||||
ata: ataResult,
|
||||
std: std,
|
||||
etd: etdResult,
|
||||
atd: atdResult,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user