-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathDateTime.test.ts
More file actions
54 lines (47 loc) · 2.23 KB
/
DateTime.test.ts
File metadata and controls
54 lines (47 loc) · 2.23 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
import { describe, it, expect } from "vitest";
import { formatDateTimeISO } from "~/components/primitives/DateTime";
describe("formatDateTimeISO", () => {
it("should format UTC dates with Z suffix", () => {
const date = new Date("2025-04-29T14:01:19.000Z");
const result = formatDateTimeISO(date, "UTC");
expect(result).toBe("2025-04-29T14:01:19.000Z");
});
describe("British Time (Europe/London)", () => {
it("should format with +01:00 during BST (summer)", () => {
// BST - British Summer Time (last Sunday in March to last Sunday in October)
const summerDate = new Date("2025-07-15T14:01:19.000Z");
const result = formatDateTimeISO(summerDate, "Europe/London");
expect(result).toBe("2025-07-15T15:01:19.000+01:00");
});
it("should format with +00:00 during GMT (winter)", () => {
// GMT - Greenwich Mean Time (winter)
const winterDate = new Date("2025-01-15T14:01:19.000Z");
const result = formatDateTimeISO(winterDate, "Europe/London");
expect(result).toBe("2025-01-15T14:01:19.000+00:00");
});
});
describe("US Pacific Time (America/Los_Angeles)", () => {
it("should format with -07:00 during PDT (summer)", () => {
// PDT - Pacific Daylight Time (second Sunday in March to first Sunday in November)
const summerDate = new Date("2025-07-15T14:01:19.000Z");
const result = formatDateTimeISO(summerDate, "America/Los_Angeles");
expect(result).toBe("2025-07-15T07:01:19.000-07:00");
});
it("should format with -08:00 during PST (winter)", () => {
// PST - Pacific Standard Time (winter)
const winterDate = new Date("2025-01-15T14:01:19.000Z");
const result = formatDateTimeISO(winterDate, "America/Los_Angeles");
expect(result).toBe("2025-01-15T06:01:19.000-08:00");
});
});
it("should preserve milliseconds", () => {
const date = new Date("2025-04-29T14:01:19.123Z");
const result = formatDateTimeISO(date, "UTC");
expect(result).toBe("2025-04-29T14:01:19.123Z");
});
it("should preserve milliseconds, not UTC", () => {
const date = new Date("2025-04-29T14:01:19.123Z");
const result = formatDateTimeISO(date, "Europe/London");
expect(result).toBe("2025-04-29T15:01:19.123+01:00");
});
});