From 8bfc4aee0f89d0a13c3c6152ce9d6cb5f23c958b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 18 Mar 2019 13:40:48 +0100 Subject: [PATCH] test for parseDateTime :white_check_mark: --- test/common.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/common.js b/test/common.js index 0db48df3..cd3d8307 100644 --- a/test/common.js +++ b/test/common.js @@ -4,6 +4,7 @@ const test = require('tape') const createClient = require('..') const vbbProfile = require('../p/vbb') +const parseDateTime = require('../parse/date-time') // todo: use a mock profile const client = createClient(vbbProfile, 'public-transport/hafas-client:test') @@ -13,3 +14,33 @@ test('exposes the profile', (t) => { t.equal(client.profile.endpoint, vbbProfile.endpoint) t.end() }) + +test('parseDateTime: works', (t) => { + const profile = {timezone: 'Europe/Berlin', locale: 'de-DE'} + const whenStr = '2019-03-18T13:19:10.000+01:00' + const when = +new Date(whenStr) + + const assert = (args, expected) => { + const name = args.join(', ') + const actual = parseDateTime(profile, ...args) + t.equal(typeof actual, typeof expected, name) + t.equal(actual, expected, name) + } + + assert(['20190318', '131910', null, false], whenStr) + assert(['20190318', '131910', null, true], when) + + // manual timezone offset + assert(['20190318', '131910', 60, false], whenStr) + assert(['20190318', '131910', 60, true], when) + assert(['20190318', '131910', 120, false], '2019-03-18T13:19:10.000+02:00') + assert(['20190318', '131910', 120, true], +new Date('2019-03-18T13:19:10.000+02:00')) + + // day offset + assert(['20190318', '2131910', null, false], '2019-03-20T13:19:10.000+01:00') + assert(['20190318', '2131910', null, true], +new Date('2019-03-20T13:19:10.000+01:00')) + assert(['20190318', '02131910', null, false], '2019-03-20T13:19:10.000+01:00') + assert(['20190318', '02131910', null, true], +new Date('2019-03-20T13:19:10.000+01:00')) + + t.end() +})