From f6687db926e03eb44e5d72d321021f7738600357 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 8 Sep 2026 09:56:55 +0200 Subject: Anchor routine due dates on UTC calendar days Daily routine done yesterday is due today regardless of time of day; same anchoring in health series so chart and badge agree. --- src/lib/shared/routine-metrics.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/lib/shared/routine-metrics.test.ts') diff --git a/src/lib/shared/routine-metrics.test.ts b/src/lib/shared/routine-metrics.test.ts index a63069c..1df39ab 100644 --- a/src/lib/shared/routine-metrics.test.ts +++ b/src/lib/shared/routine-metrics.test.ts @@ -63,6 +63,21 @@ describe('computeRoutineState', () => { const state = computeRoutineState(routine, [], now); expect(state.health).toBe(75); }); + it('is due the calendar day after completion for a daily routine', () => { + const daily = { ...routine, frequencyDays: 1 }; + const doneAt = '2026-09-07T20:00:00.000Z'; // yesterday evening + const now = Date.parse('2026-09-08T08:00:00.000Z'); // this morning, <24h later + const state = computeRoutineState(daily, [{ routineId: 1, doneAt }], now); + expect(state.status).toBe('due'); + }); + + it('is ok later the same day it was done for a daily routine', () => { + const daily = { ...routine, frequencyDays: 1 }; + const doneAt = '2026-09-08T08:00:00.000Z'; + const now = Date.parse('2026-09-08T20:00:00.000Z'); + const state = computeRoutineState(daily, [{ routineId: 1, doneAt }], now); + expect(state.status).toBe('ok'); + }); }); describe('computeHealthSeries', () => { -- cgit v1.3