-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathtime.test.ts
More file actions
46 lines (37 loc) · 1.33 KB
/
time.test.ts
File metadata and controls
46 lines (37 loc) · 1.33 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
import { expect, test } from "vitest";
import { __testing__ } from "./time";
const { parseDate } = __testing__;
test("13-digit Unix timestamp", () => {
expect(parseDate("1724938577059")).toEqual(
new Date("2024-08-29T13:36:17.059Z")
);
});
test("10-digit Unix timestamp ", () => {
expect(parseDate("1724938577")).toEqual(new Date("2024-08-29T13:36:17.000Z"));
});
test("maximum 32-bit signed integer timestamp", () => {
expect(parseDate("2147483647")).toEqual(new Date("2038-01-19T03:14:07.000Z"));
});
test("far future date", () => {
expect(parseDate("9999999999999")).toEqual(
new Date("2286-11-20T17:46:39.999Z")
);
});
test("parse ISO date string", () => {
expect(parseDate("2024-08-29T13:36:17.000Z")).toEqual(
new Date("2024-08-29T13:36:17.000Z")
);
});
// does not play well with timezones
test.skip("parse short date", () => {
expect(parseDate("2024.10")).toEqual(new Date("2024-10-01T00:00:00.000Z"));
expect(parseDate("2024/10")).toEqual(new Date("2024-10-01T00:00:00.000Z"));
expect(parseDate("2024-10")).toEqual(new Date("2024-10-01T00:00:00.000Z"));
expect(parseDate("2024")).toEqual(new Date("2024-01-01T00:00:00.000Z"));
});
test("empty string", () => {
expect(parseDate("")).toEqual(undefined);
});
test("invalid date string", () => {
expect(parseDate("whatever that is")).toEqual(undefined);
});