Skip to content

Commit a299c1b

Browse files
authored
test: dst duration date-fns bug (#2155)
1 parent 2c6da83 commit a299c1b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/features/labels/Ago.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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";
33

44
import { formatRelativeToNow } from "./Ago";
55

@@ -109,4 +109,35 @@ describe("formatRelativeToNow Function", () => {
109109
}
110110
});
111111
});
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+
});
112143
});

0 commit comments

Comments
 (0)