diff --git a/format/date.js b/format/date.js index e4d37563..d26ebbc2 100644 --- a/format/date.js +++ b/format/date.js @@ -16,7 +16,7 @@ const formatDate = (profile, when) => { locale: profile.locale, zone: timezone, }) - .toFormat('yyyyMMdd'); + .toFormat('yyyy-MM-dd'); }; export { diff --git a/format/station-board-req.js b/format/station-board-req.js index acc93fb5..604bb557 100644 --- a/format/station-board-req.js +++ b/format/station-board-req.js @@ -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) => { diff --git a/format/time.js b/format/time.js index aa4b7525..45b657e1 100644 --- a/format/time.js +++ b/format/time.js @@ -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 +}; + + diff --git a/p/db/products.js b/p/db/products.js index 06dbcd08..d78eb83c 100644 --- a/p/db/products.js +++ b/p/db/products.js @@ -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, }, ];