-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathdates.test.ts
More file actions
57 lines (53 loc) · 1.98 KB
/
dates.test.ts
File metadata and controls
57 lines (53 loc) · 1.98 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
import { convertDateToUserTz, convertTz } from "app/utils/dates"
describe("convertTz Test suite", () => {
it("should convert date to user tz if there is a difference (1h)", () => {
const date = new Date()
const serverTz = "Europe/London"
const convertedServerDate = convertTz(date, serverTz)
const userTz = "Europe/Berlin"
const convertedClientDate = convertTz(date, userTz)
const differenceInMinutes = Math.round(
Math.abs(convertedClientDate.getTime() - convertedServerDate.getTime()) / 60000
)
expect(differenceInMinutes).toBe(60)
})
it("should stay the same if no difference", () => {
const date = new Date()
const serverTz = "Europe/London"
const convertedServerDate = convertTz(date, serverTz)
const userTz = "Europe/London"
const convertedClientDate = convertTz(date, userTz)
const differenceInMinutes = Math.round(
Math.abs(convertedClientDate.getTime() - convertedServerDate.getTime()) / 60000
)
expect(differenceInMinutes).toBe(0)
})
})
describe("convertDateToUserTz Test suite", () => {
it("should convert date to user tz if there is a difference", () => {
const request = new Request("http://localhost:3000", {
headers: {
"CH-time-zone": "Europe/London",
},
method: "GET",
})
const date = new Date()
const serverDate = convertTz(date, "Europe/Berlin")
const clientDate = convertDateToUserTz(date, request)
const differenceInMinutes = Math.round(Math.abs(clientDate.getTime() - serverDate.getTime()) / 60000)
expect(differenceInMinutes).toBe(60)
})
it("should convert date to user tz if there is a difference", () => {
const request = new Request("http://localhost:3000", {
headers: {
"CH-time-zone": "Europe/London",
},
method: "GET",
})
const date = new Date()
const serverDate = convertTz(date, "Europe/London")
const clientDate = convertDateToUserTz(date, request)
const differenceInMinutes = Math.round(Math.abs(clientDate.getTime() - serverDate.getTime()) / 60000)
expect(differenceInMinutes).toBe(0)
})
})