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.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/shared/date.ts') diff --git a/src/shared/date.ts b/src/shared/date.ts index 583d2a6..3b34f14 100644 --- a/src/shared/date.ts +++ b/src/shared/date.ts @@ -1,3 +1,24 @@ +/** + * Returns the start-of-day boundary for the current study day. + * + * The "study day" is defined as 3:00 AM to the next day's 3:00 AM. + * + * - If current time >= 3:00 AM, start = today 3:00 AM local time + * - If current time < 3:00 AM, start = yesterday 3:00 AM local time + */ +export function getStartOfStudyDayBoundary(now: Date = new Date()): Date { + const boundary = new Date(now); + boundary.setMinutes(0, 0, 0); + + if (boundary.getHours() < 3) { + // Move to previous day + boundary.setDate(boundary.getDate() - 1); + } + + boundary.setHours(3); + return boundary; +} + /** * Returns the end-of-day boundary for due card comparison. * -- cgit v1.3-1-g0d28