2019-09-03 15:35:12 +02:00
|
|
|
'use strict'
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
const tap = require('tap')
|
2019-09-03 15:35:12 +02:00
|
|
|
const parse = require('../../parse/date-time')
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const ctx = {
|
|
|
|
common: {},
|
|
|
|
opt: {},
|
|
|
|
profile: {
|
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
locale: 'de-DE'
|
|
|
|
}
|
2019-09-03 15:35:12 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing returns a timestamp', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse(ctx, '20190819', '203000', undefined, false)
|
|
|
|
const ts = parse(ctx, '20190819', '203000', undefined, true)
|
2019-09-03 15:35:12 +02:00
|
|
|
t.equal(ts, +new Date(iso))
|
|
|
|
t.equal(ts, 1566239400 * 1000)
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing uses tzOffset', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse(ctx, '20190819', '203000', -120, false)
|
2019-09-03 15:35:12 +02:00
|
|
|
t.equal(iso, '2019-08-19T20:30:00-02:00')
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing works with day "overflow"', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse(ctx, '20190819', '02203000', undefined, false)
|
2019-09-03 15:35:12 +02:00
|
|
|
t.equal(iso, '2019-08-21T20:30:00+02:00')
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
|
|
|
// #106
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing works with day "overflow" & tzOffset', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse(ctx, '20190819', '02203000', -120, false)
|
2019-09-03 15:35:12 +02:00
|
|
|
t.equal(iso, '2019-08-21T20:30:00-02:00')
|
|
|
|
t.end()
|
|
|
|
})
|
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing works with summer & winter time', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse(ctx, '20190219', '203000', undefined, false)
|
2019-09-03 15:35:12 +02:00
|
|
|
t.equal(iso, '2019-02-19T20:30:00+01:00')
|
|
|
|
t.end()
|
|
|
|
})
|
2019-10-20 00:19:11 +02:00
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('date & time parsing uses profile.timezone', (t) => {
|
2019-10-20 00:19:11 +02:00
|
|
|
const iso = parse({
|
|
|
|
...ctx,
|
|
|
|
profile: {...ctx.profile, timezone: 'Europe/Moscow'}
|
|
|
|
}, '20190819', '203000', undefined, false)
|
|
|
|
t.equal(iso, '2019-08-19T20:30:00+03:00')
|
|
|
|
t.end()
|
|
|
|
})
|