diff --git a/parse/warning.js b/parse/warning.js index 810ab672..8a3007d4 100644 --- a/parse/warning.js +++ b/parse/warning.js @@ -18,13 +18,15 @@ const parseMsgEdge = (ctx) => (e) => { res.toLocation = Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null return res } + +const fallbackTime = '000000' // midnight const parseMsgEvent = (ctx) => (e) => { const {profile} = ctx // todo: test that covers this return { fromLocation: Array.isArray(e.fromLocations) && e.fromLocations[0] || e.fromLocation || null, toLocation: Array.isArray(e.toLocations) && e.toLocations[0] || e.toLocation || null, - start: profile.parseDateTime(ctx, e.fDate, e.fTime, null), - end: profile.parseDateTime(ctx, e.tDate, e.tTime, null), + start: profile.parseDateTime(ctx, e.fDate, e.fTime || fallbackTime, null), + end: profile.parseDateTime(ctx, e.tDate, e.tTime || fallbackTime, null), sections: e.sectionNums || [] // todo: parse } } diff --git a/test/parse/warning.js b/test/parse/warning.js index 5093cdeb..dc813859 100644 --- a/test/parse/warning.js +++ b/test/parse/warning.js @@ -2,6 +2,7 @@ const tap = require('tap') const parse = require('../../parse/warning') +const merge = require('lodash/merge') const profile = { parseProductsBitmask: (_, bitmask) => [bitmask], @@ -63,6 +64,57 @@ tap.test('parses warnings correctly', (t) => { modified: '20190101:084020' }) - // todo: .edges, .events + // events + const ctxWithHimMsgEventL = { + ...ctx, + res: { + common: { + himMsgEventL: [{ + fDate: '20211111', fTime: '123456', + tDate: '20211221', tTime: '012345', + }], + }, + }, + } + const inputWithEventRefL = { + ...input, + eventRefL: [0], + } + const expectedWithEvents = { + ...expected, + events: [{ + fromLocation: null, + toLocation: null, + start: '20211111:123456', + end: '20211221:012345', + sections: [], + }], + } + t.same(parse( + ctxWithHimMsgEventL, + inputWithEventRefL, + ), expectedWithEvents) + // without res.common.himMsgEventL[].{f,t}Time + t.same(parse( + merge(ctxWithHimMsgEventL, { + res: { + common: { + himMsgEventL: [{ + fTime: null, + tTime: null, + }], + }, + }, + }), + inputWithEventRefL, + ), merge(expectedWithEvents, { + events: [{ + start: '20211111:000000', + end: '20211221:000000', + }] + })) + + // todo: .edges + t.end() })