From d4489f24a05911d1395e8473fe86c3442d9397ee Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Feb 2026 12:22:03 +0000 Subject: fix(study): use date-based comparison with 3 AM boundary for due cards Instead of comparing due timestamps exactly (card.due <= now), compare against the next 3 AM boundary so all cards due within the current study day appear at once. This prevents new cards from trickling in throughout the day when FSRS fuzz spreads due times. https://claude.ai/code/session_01FeDztLcyGofd6nxh8ct7a3 --- src/shared/date.test.ts | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/shared/date.test.ts (limited to 'src/shared/date.test.ts') diff --git a/src/shared/date.test.ts b/src/shared/date.test.ts new file mode 100644 index 0000000..1c61a15 --- /dev/null +++ b/src/shared/date.test.ts @@ -0,0 +1,58 @@ +import { describe, expect, it } from "vitest"; +import { getEndOfStudyDayBoundary } from "./date"; + +describe("getEndOfStudyDayBoundary", () => { + it("should return next day 3:00 AM when current time is after 3:00 AM", () => { + // Feb 2, 2026 10:00 AM + const now = new Date(2026, 1, 2, 10, 0, 0, 0); + const boundary = getEndOfStudyDayBoundary(now); + + expect(boundary.getFullYear()).toBe(2026); + expect(boundary.getMonth()).toBe(1); + expect(boundary.getDate()).toBe(3); + expect(boundary.getHours()).toBe(3); + expect(boundary.getMinutes()).toBe(0); + expect(boundary.getSeconds()).toBe(0); + }); + + it("should return today 3:00 AM when current time is before 3:00 AM", () => { + // Feb 2, 2026 1:30 AM + const now = new Date(2026, 1, 2, 1, 30, 0, 0); + const boundary = getEndOfStudyDayBoundary(now); + + expect(boundary.getFullYear()).toBe(2026); + expect(boundary.getMonth()).toBe(1); + expect(boundary.getDate()).toBe(2); + expect(boundary.getHours()).toBe(3); + expect(boundary.getMinutes()).toBe(0); + expect(boundary.getSeconds()).toBe(0); + }); + + it("should return next day 3:00 AM when current time is exactly 3:00 AM", () => { + // Feb 2, 2026 3:00 AM + const now = new Date(2026, 1, 2, 3, 0, 0, 0); + const boundary = getEndOfStudyDayBoundary(now); + + expect(boundary.getDate()).toBe(3); + expect(boundary.getHours()).toBe(3); + }); + + it("should return next day 3:00 AM when current time is 11:59 PM", () => { + // Feb 2, 2026 11:59 PM + const now = new Date(2026, 1, 2, 23, 59, 0, 0); + const boundary = getEndOfStudyDayBoundary(now); + + expect(boundary.getDate()).toBe(3); + expect(boundary.getHours()).toBe(3); + }); + + it("should handle month boundaries correctly", () => { + // Jan 31, 2026 15:00 + const now = new Date(2026, 0, 31, 15, 0, 0, 0); + const boundary = getEndOfStudyDayBoundary(now); + + expect(boundary.getMonth()).toBe(1); // February + expect(boundary.getDate()).toBe(1); + expect(boundary.getHours()).toBe(3); + }); +}); -- cgit v1.3-1-g0d28