dbnav boards wip

This commit is contained in:
Traines 2024-12-16 21:33:10 +00:00
parent 175b166864
commit e87acc3e24
4 changed files with 52 additions and 5 deletions

View file

@ -16,7 +16,7 @@ const formatDate = (profile, when) => {
locale: profile.locale, locale: profile.locale,
zone: timezone, zone: timezone,
}) })
.toFormat('yyyyMMdd'); .toFormat('yyyy-MM-dd');
}; };
export { export {

View file

@ -15,6 +15,25 @@ const formatStationBoardReq = (ctx, station, type) => {
}; };
}; };
/*
TODO separate DB Nav profile?
const formatStationBoardReq = (ctx, station, type) => {
const { profile, opt } = ctx;
return {
endpoint: profile.boardEndpoint,
path: type == 'departures' ? 'abfahrt' : 'ankunft',
body: { "anfragezeit": profile.formatTime(profile, opt.when), "datum": profile.formatDate(profile, opt.when), "ursprungsBahnhofId": profile.formatStation(station).lid, "verkehrsmittel": profile.formatProductsFilter(ctx, opt.products || {}, 'dbnav') },
method: 'POST',
header: {
'Accept': 'application/x.db.vendo.mob.bahnhofstafeln.v2+json',
'X-Correlation-ID': 'null',
'Content-Type': 'application/x.db.vendo.mob.bahnhofstafeln.v2+json'
}
};
};
*/
/* /*
TODO separate RIS::Boards profile? TODO separate RIS::Boards profile?
const formatRisStationBoardReq = (ctx, station, type) => { const formatRisStationBoardReq = (ctx, station, type) => {

View file

@ -1,8 +1,7 @@
import {DateTime, IANAZone} from 'luxon'; import {DateTime, IANAZone} from 'luxon';
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'; import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';
// todo: change to `(profile) => (when) => {}` const getTimezone = (profile) => {
const formatTime = (profile, when, includeOffset = false) => {
let timezone; let timezone;
if (timezones.has(profile)) { if (timezones.has(profile)) {
timezone = timezones.get(profile); timezone = timezones.get(profile);
@ -10,6 +9,11 @@ const formatTime = (profile, when, includeOffset = false) => {
timezone = new IANAZone(profile.timezone); timezone = new IANAZone(profile.timezone);
timezones.set(profile, timezone); timezones.set(profile, timezone);
} }
return timezone;
}
const formatIsoDateTime = (profile, when, includeOffset = false) => {
const timezone = getTimezone(profile);
return DateTime return DateTime
.fromMillis(Number(when), { .fromMillis(Number(when), {
@ -20,6 +24,20 @@ const formatTime = (profile, when, includeOffset = false) => {
.toISO({includeOffset: includeOffset, suppressMilliseconds: true}); .toISO({includeOffset: includeOffset, suppressMilliseconds: true});
}; };
export { const formatTime = (profile, when) => {
formatTime, const timezone = getTimezone(profile);
return DateTime
.fromMillis(Number(when), {
locale: profile.locale,
zone: timezone,
})
.toFormat('HH:mm');
}; };
export {
formatIsoDateTime,
formatTime
};

View file

@ -7,6 +7,7 @@ const products = [
short: 'ICE', short: 'ICE',
vendo: 'ICE', vendo: 'ICE',
ris: 'HIGH_SPEED_TRAIN', ris: 'HIGH_SPEED_TRAIN',
dbnav: 'HOCHGESCHWINDIGKEITSZUEGE',
default: true, default: true,
}, },
{ {
@ -17,6 +18,7 @@ const products = [
short: 'IC/EC', short: 'IC/EC',
vendo: 'EC_IC', vendo: 'EC_IC',
ris: 'INTERCITY_TRAIN', ris: 'INTERCITY_TRAIN',
dbnav: 'INTERCITYUNDEUROCITYZUEGE',
default: true, default: true,
}, },
{ {
@ -27,6 +29,7 @@ const products = [
short: 'RE/IR', short: 'RE/IR',
vendo: 'IR', vendo: 'IR',
ris: 'INTER_REGIONAL_TRAIN', ris: 'INTER_REGIONAL_TRAIN',
dbnav: 'INTERREGIOUNDSCHNELLZUEGE',
default: true, default: true,
}, },
{ {
@ -37,6 +40,7 @@ const products = [
short: 'RB', short: 'RB',
vendo: 'REGIONAL', vendo: 'REGIONAL',
ris: 'REGIONAL_TRAIN', ris: 'REGIONAL_TRAIN',
dbnav: 'NAHVERKEHRSONSTIGEZUEGE',
default: true, default: true,
}, },
{ {
@ -47,6 +51,7 @@ const products = [
short: 'S', short: 'S',
vendo: 'SBAHN', vendo: 'SBAHN',
ris: 'CITY_TRAIN', ris: 'CITY_TRAIN',
dbnav: 'SBAHNEN',
default: true, default: true,
}, },
{ {
@ -57,6 +62,7 @@ const products = [
short: 'B', short: 'B',
vendo: 'BUS', vendo: 'BUS',
ris: 'BUS', ris: 'BUS',
dbnav: 'BUSSE',
default: true, default: true,
}, },
{ {
@ -67,6 +73,7 @@ const products = [
short: 'F', short: 'F',
vendo: 'SCHIFF', vendo: 'SCHIFF',
ris: 'FERRY', ris: 'FERRY',
dbnav: 'SCHIFFE',
default: true, default: true,
}, },
{ {
@ -77,6 +84,7 @@ const products = [
short: 'U', short: 'U',
vendo: 'UBAHN', vendo: 'UBAHN',
ris: 'SUBWAY', ris: 'SUBWAY',
dbnav: 'UBAHN',
default: true, default: true,
}, },
{ {
@ -87,6 +95,7 @@ const products = [
short: 'T', short: 'T',
vendo: 'TRAM', vendo: 'TRAM',
ris: 'TRAM', ris: 'TRAM',
dbnav: 'STRASSENBAHN',
default: true, default: true,
}, },
{ {
@ -97,6 +106,7 @@ const products = [
short: 'Taxi', short: 'Taxi',
vendo: 'ANRUFPFLICHTIG', vendo: 'ANRUFPFLICHTIG',
ris: 'TAXI', ris: 'TAXI',
dbnav: 'ANRUFPFLICHTIGEVERKEHRE',
default: true, default: true,
}, },
]; ];