|
1 | 1 | import { subDays, subMinutes, subMonths, subSeconds, subYears } from "date-fns"; |
2 | | -import { describe, expect, it } from "vitest"; |
| 2 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 |
|
4 | 4 | import { formatRelativeToNow } from "./Ago"; |
5 | 5 |
|
@@ -109,4 +109,35 @@ describe("formatRelativeToNow Function", () => { |
109 | 109 | } |
110 | 110 | }); |
111 | 111 | }); |
| 112 | + |
| 113 | + describe("DST/future date edge cases", () => { |
| 114 | + afterEach(() => { |
| 115 | + vi.useRealTimers(); |
| 116 | + vi.unstubAllEnvs(); |
| 117 | + }); |
| 118 | + |
| 119 | + beforeEach(() => { |
| 120 | + vi.stubEnv("TZ", "America/Chicago"); |
| 121 | + }); |
| 122 | + |
| 123 | + it.todo("does not product weird 0.09999999999999998y value", () => { |
| 124 | + // This test reproduces the EXACT bug the user saw by using real dates + DST transition |
| 125 | + // https://lemmy.ml/post/38394736 |
| 126 | + // https://github.com/date-fns/date-fns/issues/3896 |
| 127 | + // Maybe fixed by switching to temporal api eventually |
| 128 | + |
| 129 | + // Mock the current time |
| 130 | + const mockNow = new Date("2025-11-02T06:59:59.999Z"); |
| 131 | + vi.useFakeTimers(); |
| 132 | + vi.setSystemTime(mockNow); |
| 133 | + |
| 134 | + // Create a date that's slightly in the future of DST transition |
| 135 | + const slightlyFuture = new Date("2025-11-02T07:00:00.000Z"); |
| 136 | + |
| 137 | + // Test what formatRelativeToNow produces |
| 138 | + const result = formatRelativeToNow(slightlyFuture, "ultrashort"); |
| 139 | + |
| 140 | + expect(result).toBe("<1s"); |
| 141 | + }); |
| 142 | + }); |
112 | 143 | }); |
0 commit comments