forked from giuseppeg/refined-twitter-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
29 lines (26 loc) · 1.12 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const assert = require('assert')
function dnd(dnd, nowTimestamp) {
const [start, end] = dnd.map(time => {
const [h, m] = time.split(':').map(Number)
const t = new Date(nowTimestamp)
t.setHours(h)
t.setMinutes(m)
return t
})
const now = new Date(nowTimestamp)
return (now >= start || (start >= end && now <= start && now <= end)) && (now <= end || end <= start)
}
function getTime(time) {
const d = new Date()
const [h, m] = time.split(':').map(Number)
d.setHours(h)
d.setMinutes(m)
return d
}
assert.ok(!dnd(['2:00', '3:00'], getTime('1:00').getTime()), 'off: same day before')
assert.ok(!dnd(['2:00', '3:00'], getTime('4:00').getTime()), 'off: same day after')
assert.ok(!dnd(['21:00', '9:30'], getTime('9:40').getTime()), 'off: same day from yesterday')
assert.ok(!dnd(['21:00', '9:30'], getTime('20:00').getTime()), 'off: same day with tomorrow')
assert.ok(dnd(['2:00', '4:15'], getTime('4:00').getTime()), 'on: same day')
assert.ok(dnd(['22:00', '4:15'], getTime('22:00').getTime()), 'on: same day to tomorrow')
assert.ok(dnd(['22:00', '4:15'], getTime('2:00').getTime()), 'on: same day from yesterday')