-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
66 lines (54 loc) · 1.45 KB
/
test.ts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import test from "ava";
import tizo from "./index";
const localOffset = new Date().getTimezoneOffset();
const addOffset = (
[hours, minutes]: [number, number],
offset: number
): [number, number] => {
const tmpDate = new Date();
tmpDate.setHours(hours);
tmpDate.setMinutes(minutes - localOffset);
return [tmpDate.getHours(), tmpDate.getMinutes()];
};
test("original", t => {
t.deepEqual(tizo("19:30 CET").original, [19, 30]);
});
test("utc", t => {
t.deepEqual(tizo("19:30 PDT").utc, [2, 30]);
});
test("local", t => {
t.deepEqual(tizo("19:30 AWST").local, addOffset([11, 30], localOffset));
});
test("complicated timezones", t => {
t.deepEqual(tizo("2:15 ACDT").utc, [15, 45]);
});
test("no timezone", t => {
t.deepEqual(tizo("2:15").utc, [2, 15]);
});
test("weird format", t => {
t.deepEqual(tizo(" dfae:§ 04 30 pM pDt ssss").utc, [23, 30]);
});
test("throw if unrecognised", t => {
t.throws(() => tizo(""));
});
test("am/pm", t => {
t.deepEqual(tizo("11am").utc, [11, 0]);
t.deepEqual(tizo("12am").utc, [0, 0]);
t.deepEqual(tizo("11pm").utc, [23, 0]);
t.deepEqual(tizo("12pm").utc, [12, 0]);
});
test("get input timezone", t => {
t.deepEqual(tizo("09 30 pt").inputTimezone, {
name: "Pacific Time",
offset: -8,
});
});
test("default input timezone", t => {
t.deepEqual(tizo("9").inputTimezone, {
name: "",
offset: 0,
});
});
test("throws if unrecognized timezone", t => {
t.throws(() => tizo("12 am ooooot"));
});