aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shared/date.ts
diff options
context:
space:
mode:
authorClaude <noreply@anthropic.com>2026-02-02 12:22:03 +0000
committerClaude <noreply@anthropic.com>2026-02-02 12:22:03 +0000
commitd4489f24a05911d1395e8473fe86c3442d9397ee (patch)
tree3f302c9c531c7ba25e2c5ad74c44b086df03a0d7 /src/shared/date.ts
parentc20922a1aa339e34b4bed3747222f4b9d9941cd6 (diff)
downloadkioku-d4489f24a05911d1395e8473fe86c3442d9397ee.tar.gz
kioku-d4489f24a05911d1395e8473fe86c3442d9397ee.tar.zst
kioku-d4489f24a05911d1395e8473fe86c3442d9397ee.zip
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
Diffstat (limited to 'src/shared/date.ts')
-rw-r--r--src/shared/date.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/date.ts b/src/shared/date.ts
new file mode 100644
index 0000000..583d2a6
--- /dev/null
+++ b/src/shared/date.ts
@@ -0,0 +1,21 @@
+/**
+ * Returns the end-of-day boundary for due card comparison.
+ *
+ * The "study day" is defined as 3:00 AM to the next day's 3:00 AM.
+ * All cards with `due < boundary` are considered due for the current study day.
+ *
+ * - If current time >= 3:00 AM, boundary = tomorrow 3:00 AM local time
+ * - If current time < 3:00 AM, boundary = today 3:00 AM local time
+ */
+export function getEndOfStudyDayBoundary(now: Date = new Date()): Date {
+ const boundary = new Date(now);
+ boundary.setMinutes(0, 0, 0);
+
+ if (boundary.getHours() >= 3) {
+ // Move to next day
+ boundary.setDate(boundary.getDate() + 1);
+ }
+
+ boundary.setHours(3);
+ return boundary;
+}