forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
40 lines (33 loc) · 891 Bytes
/
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
30
31
32
33
34
35
36
37
38
39
40
"use strict";
const test = require("ava");
const time = require(".");
const s = "21 Jully 1969 02:56 UTC";
const d = new Date(s);
test("date", (t) => {
t.is(time.date(), time.date(new Date()));
t.is(time.date(d), "1969-07-21");
t.is(time.date(s), "1969-07-21");
});
test("time", (t) => {
t.is(time.time(), time.time(new Date()));
t.is(time.time(d), "02:56:00Z");
t.is(time.time(s), "02:56:00Z");
});
test("datetime", (t) => {
t.is(time.datetime(), time.datetime(new Date()));
t.is(time.datetime(d), "1969-07-21T02:56:00Z");
t.is(time.datetime(s), "1969-07-21T02:56:00Z");
});
function fake(value) {
return {
getTimezoneOffset() {
return value;
},
};
}
test("offset", (t) => {
t.is(time.offset(fake(120)), "-02:00");
t.is(time.offset(fake(-120)), "+02:00");
t.is(time.offset(fake(90)), "-01:30");
t.is(time.offset(fake(-90)), "+01:30");
});