test for parseDateTime

This commit is contained in:
Jannis R 2019-03-18 13:40:48 +01:00 committed by Jannis Redmann
parent 29aea9a5ef
commit 8bfc4aee0f

View file

@ -4,6 +4,7 @@ const test = require('tape')
const createClient = require('..') const createClient = require('..')
const vbbProfile = require('../p/vbb') const vbbProfile = require('../p/vbb')
const parseDateTime = require('../parse/date-time')
// todo: use a mock profile // todo: use a mock profile
const client = createClient(vbbProfile, 'public-transport/hafas-client:test') 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.equal(client.profile.endpoint, vbbProfile.endpoint)
t.end() 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()
})