2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-07-23 20:42:22 +02:00
|
|
|
const {DateTime} = require('luxon')
|
2019-08-23 16:21:44 +02:00
|
|
|
const findRemarks = require('./find-remarks')
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2022-11-16 14:59:34 +01:00
|
|
|
// todo: DRY with parse/date-time.js
|
|
|
|
const parseDate = (date) => {
|
|
|
|
const res = {
|
|
|
|
year: parseInt(date.substr(-8, 4)),
|
|
|
|
month: parseInt(date.substr(-4, 2)),
|
|
|
|
day: parseInt(date.substr(-2, 2)),
|
|
|
|
}
|
|
|
|
if (!Number.isInteger(res.year) || !Number.isInteger(res.month) || !Number.isInteger(res.day)) {
|
|
|
|
throw new Error('invalid date format: ' + date)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseScheduledDays = (sDaysB, fpB, fpE, profile) => {
|
2018-07-23 20:42:22 +02:00
|
|
|
sDaysB = Buffer.from(sDaysB, 'hex')
|
|
|
|
const res = Object.create(null)
|
|
|
|
|
2022-11-16 14:59:34 +01:00
|
|
|
const _fpB = parseDate(fpB)
|
2018-07-23 20:42:22 +02:00
|
|
|
let d = DateTime.fromObject({
|
|
|
|
zone: profile.timezone, locale: profile.locale,
|
2022-11-16 14:59:34 +01:00
|
|
|
year: _fpB.year, month: _fpB.month, day: _fpB.day,
|
2018-07-23 20:42:22 +02:00
|
|
|
hour: 0, minute: 0, second: 0, millisecond: 0
|
|
|
|
})
|
|
|
|
for (let b = 0; b < sDaysB.length; b++) {
|
|
|
|
for (let i = 0; i < 8; i++) {
|
|
|
|
res[d.toISODate()] = (sDaysB[b] & Math.pow(2, 7 - i)) > 0
|
|
|
|
d = d.plus({days: 1})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
2021-11-18 18:29:25 +01:00
|
|
|
// todo: c.conSubscr (e.g. `F`)
|
2019-10-20 00:19:11 +02:00
|
|
|
// todo: c.trfRes x vbb-parse-ticket
|
|
|
|
// todo: c.sotRating, c.isSotCon, c.sotCtxt
|
|
|
|
// todo: c.showARSLink
|
|
|
|
// todo: c.useableTime
|
2021-11-18 18:29:25 +01:00
|
|
|
// todo: c.cksum (e.g. `b3a94228_3`), c.cksumDti (e.g. `c2717eb3_3`)
|
2019-10-20 00:19:11 +02:00
|
|
|
// todo: c.isNotRdbl
|
|
|
|
// todo: c.badSecRefX
|
|
|
|
// todo: c.bfATS, c.bfIOSTS
|
2021-11-18 18:29:25 +01:00
|
|
|
// todo: c.recState (e.g. `U`)
|
|
|
|
// todo: c.intvlSubscr (e.g. `F`)
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseJourney = (ctx, j) => { // j = raw jouney
|
|
|
|
const {profile, opt} = ctx
|
2017-12-07 20:21:14 +01:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const legs = j.secL.map(l => profile.parseJourneyLeg(ctx, l, j.date))
|
|
|
|
const res = {
|
|
|
|
type: 'journey',
|
|
|
|
legs,
|
2021-01-19 15:10:07 +01:00
|
|
|
refreshToken: (j.recon && j.recon.ctx) || j.ctxRecon || null
|
2019-10-20 00:19:11 +02:00
|
|
|
}
|
2018-12-02 01:05:19 +01:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const freq = j.freq || {}
|
|
|
|
if (freq.minC || freq.maxC) {
|
|
|
|
res.cycle = {}
|
|
|
|
if (freq.minC) res.cycle.min = freq.minC * 60
|
|
|
|
if (freq.maxC) res.cycle.max = freq.maxC * 60
|
|
|
|
// nr of connections in this frequency, from now on
|
|
|
|
if (freq.numC) res.cycle.nr = freq.numC
|
|
|
|
}
|
2018-06-11 11:29:32 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
if (opt.remarks && Array.isArray(j.msgL)) {
|
|
|
|
res.remarks = findRemarks(j.msgL).map(([remark]) => remark)
|
|
|
|
}
|
2018-07-23 20:42:22 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
if (opt.scheduledDays) {
|
2022-11-16 14:59:34 +01:00
|
|
|
// sDaysB is a bitmap mapping all days from fpB (first date of schedule) to fpE (last date in schedule).
|
|
|
|
const {sDaysB} = j.sDays
|
|
|
|
const {fpB, fpE} = ctx.res
|
|
|
|
if (sDaysB && fpB && fpE) {
|
|
|
|
res.scheduledDays = parseScheduledDays(sDaysB, fpB, fpE, profile)
|
|
|
|
}
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
module.exports = parseJourney
|