You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer building insight features, I want pure, unit-tested helper functions that compute a habit's completions over a date range and over the last 7 days, so that the UI layer can call them without any business-logic duplication.
Acceptance criteria
completionsInRange(habit: Habit, fromDay: string, toDay: string): number is added to src/habits.ts. fromDay and toDay are ISO-8601 date strings (YYYY-MM-DD), both inclusive. The function counts how many of the habit's completedDates fall within the range.
last7Count(habit: Habit, today: string): number is added to src/habits.ts. It returns the count of completions in the 7-day window ending on (and including) today — i.e. completionsInRange(habit, sevenDaysAgo, today).
Both helpers are pure: no DOM access, no localStorage, no window — safe to call in Vitest.
src/habits.test.ts includes tests covering: zero completions, completions inside/outside the range boundary, a full 7-day window, and partial completions.
npm test and npm run build both pass with no new type errors.
Definition of done
npm test and npm run build pass; all new logic lives in src/habits.ts; no DOM or storage access introduced.
User story
As a developer building insight features, I want pure, unit-tested helper functions that compute a habit's completions over a date range and over the last 7 days, so that the UI layer can call them without any business-logic duplication.
Acceptance criteria
completionsInRange(habit: Habit, fromDay: string, toDay: string): numberis added tosrc/habits.ts.fromDayandtoDayare ISO-8601 date strings (YYYY-MM-DD), both inclusive. The function counts how many of the habit'scompletedDatesfall within the range.last7Count(habit: Habit, today: string): numberis added tosrc/habits.ts. It returns the count of completions in the 7-day window ending on (and including)today— i.e.completionsInRange(habit, sevenDaysAgo, today).localStorage, nowindow— safe to call in Vitest.src/habits.test.tsincludes tests covering: zero completions, completions inside/outside the range boundary, a full 7-day window, and partial completions.npm testandnpm run buildboth pass with no new type errors.Definition of done
npm testandnpm run buildpass; all new logic lives insrc/habits.ts; no DOM or storage access introduced.Source: REQ-002 (vault/02 - Requirements/REQ-002 - Insight heatmap and weekly stats.md)