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,
zone: timezone,
})
.toFormat('yyyyMMdd');
.toFormat('yyyy-MM-dd');
};
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?
const formatRisStationBoardReq = (ctx, station, type) => {

View file

@ -1,8 +1,7 @@
import {DateTime, IANAZone} from 'luxon';
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';
// todo: change to `(profile) => (when) => {}`
const formatTime = (profile, when, includeOffset = false) => {
const getTimezone = (profile) => {
let timezone;
if (timezones.has(profile)) {
timezone = timezones.get(profile);
@ -10,6 +9,11 @@ const formatTime = (profile, when, includeOffset = false) => {
timezone = new IANAZone(profile.timezone);
timezones.set(profile, timezone);
}
return timezone;
}
const formatIsoDateTime = (profile, when, includeOffset = false) => {
const timezone = getTimezone(profile);
return DateTime
.fromMillis(Number(when), {
@ -20,6 +24,20 @@ const formatTime = (profile, when, includeOffset = false) => {
.toISO({includeOffset: includeOffset, suppressMilliseconds: true});
};
export {
formatTime,
const formatTime = (profile, when) => {
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',
vendo: 'ICE',
ris: 'HIGH_SPEED_TRAIN',
dbnav: 'HOCHGESCHWINDIGKEITSZUEGE',
default: true,
},
{
@ -17,6 +18,7 @@ const products = [
short: 'IC/EC',
vendo: 'EC_IC',
ris: 'INTERCITY_TRAIN',
dbnav: 'INTERCITYUNDEUROCITYZUEGE',
default: true,
},
{
@ -27,6 +29,7 @@ const products = [
short: 'RE/IR',
vendo: 'IR',
ris: 'INTER_REGIONAL_TRAIN',
dbnav: 'INTERREGIOUNDSCHNELLZUEGE',
default: true,
},
{
@ -37,6 +40,7 @@ const products = [
short: 'RB',
vendo: 'REGIONAL',
ris: 'REGIONAL_TRAIN',
dbnav: 'NAHVERKEHRSONSTIGEZUEGE',
default: true,
},
{
@ -47,6 +51,7 @@ const products = [
short: 'S',
vendo: 'SBAHN',
ris: 'CITY_TRAIN',
dbnav: 'SBAHNEN',
default: true,
},
{
@ -57,6 +62,7 @@ const products = [
short: 'B',
vendo: 'BUS',
ris: 'BUS',
dbnav: 'BUSSE',
default: true,
},
{
@ -67,6 +73,7 @@ const products = [
short: 'F',
vendo: 'SCHIFF',
ris: 'FERRY',
dbnav: 'SCHIFFE',
default: true,
},
{
@ -77,6 +84,7 @@ const products = [
short: 'U',
vendo: 'UBAHN',
ris: 'SUBWAY',
dbnav: 'UBAHN',
default: true,
},
{
@ -87,6 +95,7 @@ const products = [
short: 'T',
vendo: 'TRAM',
ris: 'TRAM',
dbnav: 'STRASSENBAHN',
default: true,
},
{
@ -97,6 +106,7 @@ const products = [
short: 'Taxi',
vendo: 'ANRUFPFLICHTIG',
ris: 'TAXI',
dbnav: 'ANRUFPFLICHTIGEVERKEHRE',
default: true,
},
];