diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 09:56:55 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 09:56:55 +0200 |
| commit | f6687db926e03eb44e5d72d321021f7738600357 (patch) | |
| tree | 3af3c99b7401c46aab5695bc7fa066621d0fd69d /src/lib/shared/routine-metrics.test.ts | |
| parent | 60475b2345b6a064fb4dee5259597d7e4569fdb7 (diff) | |
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.
Diffstat (limited to 'src/lib/shared/routine-metrics.test.ts')
| -rw-r--r-- | src/lib/shared/routine-metrics.test.ts | 15 |
1 files changed, 15 insertions, 0 deletions
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', () => { |
