mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
35 lines
715 B
JavaScript
35 lines
715 B
JavaScript
const parseWhen = (ctx, date, timeS, timeR, tzOffset, cncl = false) => {
|
|
const parse = ctx.profile.parseDateTime;
|
|
|
|
let planned = timeS
|
|
? parse(ctx, date, timeS, tzOffset, false)
|
|
: null;
|
|
let prognosed = timeR
|
|
? parse(ctx, date, timeR, tzOffset, false)
|
|
: null;
|
|
let delay = null;
|
|
|
|
if (planned && prognosed) {
|
|
const tPlanned = parse(ctx, date, timeS, tzOffset, true);
|
|
const tPrognosed = parse(ctx, date, timeR, tzOffset, true);
|
|
delay = Math.round((tPrognosed - tPlanned) / 1000);
|
|
}
|
|
|
|
if (cncl) {
|
|
return {
|
|
when: null,
|
|
plannedWhen: planned,
|
|
prognosedWhen: prognosed,
|
|
delay,
|
|
};
|
|
}
|
|
return {
|
|
when: prognosed || planned,
|
|
plannedWhen: planned,
|
|
delay,
|
|
};
|
|
};
|
|
|
|
export {
|
|
parseWhen,
|
|
};
|