mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
test for parseDateTime ✅
This commit is contained in:
parent
29aea9a5ef
commit
8bfc4aee0f
1 changed files with 31 additions and 0 deletions
|
@ -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()
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue