-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathformat-timestamp.test.ts
More file actions
94 lines (81 loc) · 2.76 KB
/
Copy pathformat-timestamp.test.ts
File metadata and controls
94 lines (81 loc) · 2.76 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
import { describe, it, expect } from "vitest";
import {
formatTimestamp,
formatTimeUTC,
formatTimeLocal,
formatScheduleTime,
formatScheduleDateTime,
} from "../format-timestamp";
describe("formatTimestamp", () => {
it("returns empty string for undefined", () => {
expect(formatTimestamp(undefined)).toBe("");
});
it("returns empty string for empty string", () => {
expect(formatTimestamp("")).toBe("");
});
it("returns empty string for invalid date", () => {
expect(formatTimestamp("not-a-date")).toBe("");
});
it("returns formatted date for valid ISO timestamp", () => {
const result = formatTimestamp("2025-02-27T17:34:00Z");
expect(result).toBeTruthy();
expect(result.length).toBeGreaterThan(0);
});
});
describe("formatTimeUTC", () => {
it("includes UTC suffix", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatTimeUTC(date);
expect(result).toContain("UTC");
});
it("formats time in UTC timezone", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatTimeUTC(date);
// Should contain 5:00 PM or 17:00 depending on locale
expect(result).toMatch(/5:00\s*PM\s*UTC|17:00\s*UTC/);
});
});
describe("formatTimeLocal", () => {
it("returns a non-empty string", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatTimeLocal(date);
expect(result).toBeTruthy();
expect(result.length).toBeGreaterThan(0);
});
it("includes a timezone abbreviation", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatTimeLocal(date);
// Should include some timezone indicator (UTC, EDT, PST, etc.)
expect(result).toMatch(/[A-Z]{2,}/);
});
});
describe("formatScheduleTime", () => {
it("includes UTC time", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatScheduleTime(date);
expect(result).toContain("UTC");
});
it("returns a non-empty string for valid date", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatScheduleTime(date);
expect(result).toBeTruthy();
});
});
describe("formatScheduleDateTime", () => {
it("includes UTC time", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatScheduleDateTime(date);
expect(result).toContain("UTC");
});
it("includes date portion", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatScheduleDateTime(date);
// Should contain a month abbreviation and day
expect(result).toMatch(/\w+\s+\d+/);
});
it("returns a non-empty string for valid date", () => {
const date = new Date("2025-06-15T17:00:00Z");
const result = formatScheduleDateTime(date);
expect(result).toBeTruthy();
});
});