|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | +import { formatDateTimeISO } from "~/components/primitives/DateTime"; |
| 3 | + |
| 4 | +describe("formatDateTimeISO", () => { |
| 5 | + it("should format UTC dates with Z suffix", () => { |
| 6 | + const date = new Date("2025-04-29T14:01:19.000Z"); |
| 7 | + const result = formatDateTimeISO(date, "UTC"); |
| 8 | + expect(result).toBe("2025-04-29T14:01:19.000Z"); |
| 9 | + }); |
| 10 | + |
| 11 | + describe("British Time (Europe/London)", () => { |
| 12 | + it("should format with +01:00 during BST (summer)", () => { |
| 13 | + // BST - British Summer Time (last Sunday in March to last Sunday in October) |
| 14 | + const summerDate = new Date("2025-07-15T14:01:19.000Z"); |
| 15 | + const result = formatDateTimeISO(summerDate, "Europe/London"); |
| 16 | + expect(result).toBe("2025-07-15T15:01:19.000+01:00"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should format with +00:00 during GMT (winter)", () => { |
| 20 | + // GMT - Greenwich Mean Time (winter) |
| 21 | + const winterDate = new Date("2025-01-15T14:01:19.000Z"); |
| 22 | + const result = formatDateTimeISO(winterDate, "Europe/London"); |
| 23 | + expect(result).toBe("2025-01-15T14:01:19.000+00:00"); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("US Pacific Time (America/Los_Angeles)", () => { |
| 28 | + it("should format with -07:00 during PDT (summer)", () => { |
| 29 | + // PDT - Pacific Daylight Time (second Sunday in March to first Sunday in November) |
| 30 | + const summerDate = new Date("2025-07-15T14:01:19.000Z"); |
| 31 | + const result = formatDateTimeISO(summerDate, "America/Los_Angeles"); |
| 32 | + expect(result).toBe("2025-07-15T07:01:19.000-07:00"); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should format with -08:00 during PST (winter)", () => { |
| 36 | + // PST - Pacific Standard Time (winter) |
| 37 | + const winterDate = new Date("2025-01-15T14:01:19.000Z"); |
| 38 | + const result = formatDateTimeISO(winterDate, "America/Los_Angeles"); |
| 39 | + expect(result).toBe("2025-01-15T06:01:19.000-08:00"); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should preserve milliseconds", () => { |
| 44 | + const date = new Date("2025-04-29T14:01:19.123Z"); |
| 45 | + const result = formatDateTimeISO(date, "UTC"); |
| 46 | + expect(result).toBe("2025-04-29T14:01:19.123Z"); |
| 47 | + }); |
| 48 | +}); |
0 commit comments