2017-11-12 21:03:24 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const isRoughlyEqual = require('is-roughly-equal')
|
2017-12-11 16:33:17 +01:00
|
|
|
const {DateTime} = require('luxon')
|
2018-05-14 00:35:21 +02:00
|
|
|
const a = require('assert')
|
2020-05-21 19:04:22 +02:00
|
|
|
const tape = require('tape')
|
2017-11-12 21:03:24 +01:00
|
|
|
|
2017-12-11 16:33:17 +01:00
|
|
|
const hour = 60 * 60 * 1000
|
2018-05-14 00:35:21 +02:00
|
|
|
const day = 24 * hour
|
|
|
|
const week = 7 * day
|
2017-11-12 21:03:24 +01:00
|
|
|
|
2017-12-11 16:33:17 +01:00
|
|
|
// next Monday 10 am
|
2017-12-28 22:57:22 +01:00
|
|
|
const createWhen = (timezone, locale) => {
|
|
|
|
return DateTime.fromMillis(Date.now(), {
|
|
|
|
zone: timezone,
|
|
|
|
locale,
|
|
|
|
}).startOf('week').plus({weeks: 1, hours: 10}).toJSDate()
|
|
|
|
}
|
2018-04-18 20:08:47 +02:00
|
|
|
|
2018-05-14 00:35:21 +02:00
|
|
|
const assertValidWhen = (actual, expected, name) => {
|
2017-12-28 22:57:22 +01:00
|
|
|
const ts = +new Date(actual)
|
2018-05-14 00:35:21 +02:00
|
|
|
a.ok(!Number.isNaN(ts), name + ' is not parsable by Date')
|
2018-04-18 20:08:47 +02:00
|
|
|
// the timestamps might be from long-distance trains
|
2020-04-09 14:53:28 +02:00
|
|
|
a.ok(isRoughlyEqual(day + 6 * hour, +expected, ts), name + ' is out of range')
|
2017-12-11 15:41:27 +01:00
|
|
|
}
|
|
|
|
|
2020-05-21 19:04:22 +02:00
|
|
|
const test = tape
|
|
|
|
|
2017-11-12 21:03:24 +01:00
|
|
|
module.exports = {
|
2020-05-21 19:04:22 +02:00
|
|
|
hour, createWhen, assertValidWhen,
|
|
|
|
test,
|
2017-11-12 21:03:24 +01:00
|
|
|
}
|