-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathweb.datetime.util.test.ts
More file actions
119 lines (94 loc) · 3.32 KB
/
web.datetime.util.test.ts
File metadata and controls
119 lines (94 loc) · 3.32 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
shouldAdjustComplimentDate,
shouldAdjustComplimentTime,
} from "@web/common/utils/datetime/web.datetime.util";
describe("Dates", () => {
it("recognizes date adjustment after changing start", () => {
const impossibleStart = shouldAdjustComplimentDate("start", {
start: new Date("2022-06-06"),
end: new Date("2022-06-04"),
});
expect(impossibleStart.shouldAdjust).toBe(true);
expect(impossibleStart.compliment).toEqual(new Date("2022-06-06"));
const sameStartAsEnd = shouldAdjustComplimentDate("start", {
start: new Date("2022-11-11"),
end: new Date("2022-11-11"),
});
expect(sameStartAsEnd.shouldAdjust).toBe(false);
const noAdjustment = shouldAdjustComplimentDate("start", {
start: new Date("2022-10-10"),
end: new Date("2022-11-11"),
});
expect(noAdjustment.shouldAdjust).toBe(false);
});
it("recognizes date adjustment after changing end", () => {
const impossibleEnd = shouldAdjustComplimentDate("end", {
start: new Date("2022-02-02"),
end: new Date("2022-01-01"),
});
expect(impossibleEnd.shouldAdjust).toBe(true);
expect(impossibleEnd.compliment).toEqual(new Date("2022-01-01"));
const sameStartAsEnd = shouldAdjustComplimentDate("end", {
start: new Date("2022-05-05"),
end: new Date("2022-05-05"),
});
expect(sameStartAsEnd.shouldAdjust).toBe(false);
const noAdjustment = shouldAdjustComplimentDate("end", {
start: new Date("2022-04-04"),
end: new Date("2022-04-05"),
});
expect(noAdjustment.shouldAdjust).toBe(false);
});
});
describe("Time Options", () => {
it("recognizes adjustment needed after changing start", () => {
const impossibleStart = shouldAdjustComplimentTime("start", {
oldStart: "1:00 AM",
oldEnd: "2:00 AM",
start: "5:00 AM",
end: "2:00 AM", // should be 600
});
expect(impossibleStart.shouldAdjust).toBe(true);
expect(impossibleStart.adjustment).toBe(240);
const sameStartAsEnd = shouldAdjustComplimentTime("start", {
oldStart: "7:00 PM",
oldEnd: "7:15 PM",
start: "7:15 PM",
end: "7:15 PM", // should be 730
});
expect(sameStartAsEnd.shouldAdjust).toBe(true);
expect(sameStartAsEnd.adjustment).toBe(15);
const noAdjustment = shouldAdjustComplimentTime("start", {
oldStart: "9:45 PM",
oldEnd: "11:45 PM",
start: "5 PM",
end: "11:45 PM",
});
expect(noAdjustment.shouldAdjust).toBe(false);
});
it("recognizes adjustment needed after changing end", () => {
const impossibleEnd = shouldAdjustComplimentTime("end", {
oldStart: "11:00 AM",
oldEnd: "2:00 PM",
start: "11:00 AM", // should be 6 PM, 5 hr adjustment
end: "9:00 AM",
});
expect(impossibleEnd.shouldAdjust).toBe(true);
expect(impossibleEnd.adjustment).toBe(60 * 5);
const sameStartAsEnd = shouldAdjustComplimentTime("end", {
oldStart: "7:00 PM",
oldEnd: "7:15 PM",
start: "7:15 PM",
end: "7:00 PM",
});
expect(sameStartAsEnd.shouldAdjust).toBe(true);
expect(sameStartAsEnd.adjustment).toBe(30);
const noAdjustment = shouldAdjustComplimentTime("end", {
oldStart: "9:45 PM",
oldEnd: "11:45 PM",
start: "5 PM",
end: "11:45 PM",
});
expect(noAdjustment.shouldAdjust).toBe(false);
});
});