Skip to content

[REQ-002] Add completionsInRange and last7Count pure helpers #5

@markoub

Description

@markoub

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): 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.

Source: REQ-002 (vault/02 - Requirements/REQ-002 - Insight heatmap and weekly stats.md)

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentCreated/handled by the autonomous pipeline

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions