From 2d617f236fa3fbd39a0a7def23199a36cfa0b4c2 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 4 Feb 2026 22:51:01 +0900 Subject: fix(study): use 3 AM boundary for counting today's new card reviews countTodayNewCardReviews was using midnight (0:00) as the start of day, inconsistent with the 3 AM study day boundary used elsewhere. Reviews between 0:00-3:00 AM were incorrectly counted as the next day's budget. Co-Authored-By: Claude Opus 4.5 --- src/shared/date.test.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/shared/date.test.ts') diff --git a/src/shared/date.test.ts b/src/shared/date.test.ts index 1c61a15..da832f5 100644 --- a/src/shared/date.test.ts +++ b/src/shared/date.test.ts @@ -1,5 +1,52 @@ import { describe, expect, it } from "vitest"; -import { getEndOfStudyDayBoundary } from "./date"; +import { getEndOfStudyDayBoundary, getStartOfStudyDayBoundary } from "./date"; + +describe("getStartOfStudyDayBoundary", () => { + it("should return today 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 = getStartOfStudyDayBoundary(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 yesterday 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 = getStartOfStudyDayBoundary(now); + + expect(boundary.getFullYear()).toBe(2026); + expect(boundary.getMonth()).toBe(1); + expect(boundary.getDate()).toBe(1); + 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 exactly 3:00 AM", () => { + // Feb 2, 2026 3:00 AM + const now = new Date(2026, 1, 2, 3, 0, 0, 0); + const boundary = getStartOfStudyDayBoundary(now); + + expect(boundary.getDate()).toBe(2); + expect(boundary.getHours()).toBe(3); + }); + + it("should handle month boundaries correctly", () => { + // Feb 1, 2026 1:00 AM + const now = new Date(2026, 1, 1, 1, 0, 0, 0); + const boundary = getStartOfStudyDayBoundary(now); + + expect(boundary.getMonth()).toBe(0); // January + expect(boundary.getDate()).toBe(31); + expect(boundary.getHours()).toBe(3); + }); +}); describe("getEndOfStudyDayBoundary", () => { it("should return next day 3:00 AM when current time is after 3:00 AM", () => { -- cgit v1.3-1-g0d28