Skip to content

feat(overview): load statistics for any local date range - #4

Merged
AritxOnly merged 3 commits into
DeadlinerStudio:byosfrom
Tequilaar:mac/overview-date-range
Nov 3, 2026
Merged

AritxOnly merged 3 commits into
DeadlinerStudio:byosfrom
Tequilaar:mac/overview-date-range

Conversation

@Tequilaar

Copy link
Copy Markdown

背景

各端的时间范围选择目前只能用 Core 的固定窗口(近 7 天、近 4 周、近 12 个月、150 天热力图)或整月(loadMonthNow)。用户希望可以选任意起止日期,例如 10 月 12 日到 12 月 31 日。这类统计应该由 Core 计算,平台不重复实现。

改动

  • OverviewViewModel.loadRangeNow(startDate, endDateExclusive):读取本地日期范围 [start, endExclusive) 的统计。
    • 内部的 buildRangeState 与 buildMonthState 使用相同的规则:完成按实际完成日期,其他状态和各项指标按截止日期。
    • 对比使用前一个等长时段。比如 81 天的范围,就和它之前的 81 天比。
    • 范围限制为 1~3660 天,不合法时抛出 IllegalArgumentException。
  • 新增 OverviewRangeUiState,包含:每天的数据(范围内每一天,今天之后的日期没有完成记录)、状态分布、完成时间段、指标(OverviewMonthlyMetrics)、范围内完成的任务。
  • Apple 状态桥 IosOverviewStateBridge.loadRange(startDate, endDateExclusive, onState, onError):与 loadMonth 写法一致,错误通过 onError 返回,不会让应用退出。
  • 新增私有辅助函数 taskTimes,只在范围统计中使用;buildMonthState 没有改动。

测试

新增 3 个测试:

  • wholeMonthRangeMatchesMonthlyProjection:范围恰好是一整月时,结果与 buildMonthState 完全一致(状态分布、完成数、每日数据);完成时间段的合计等于完成数。
  • customRangeSpansMonthsIntoTheFutureAndComparesWithPrecedingPeriod:10 月 12 日~12 月 31 日(81 天)跨月且延伸到未来。验证每日数据条数、完成数、状态分布、完成时间段、前一时段的任务数,以及范围内完成的任务。
  • emptyOrReversedRangesAreRejected。

验证

  • ./gradlew -PlifiMode=stub :shared:macosArm64Test:277 个测试全部通过(原 274 + 新增 3)。
  • ./gradlew -PlifiMode=private :shared:macosArm64Test:331 个测试全部通过(原 328 + 新增 3)。
  • Mac 客户端的概览、趋势和菜单栏都已使用这个接口,单元测试中用 Core 读取自定义范围。

影响

  • 只新增,不修改已有的公开接口。
  • Apple 头文件新增 OverviewRangeUiState 和 loadRange。
  • 与 build(apple): share iOS state bridges with macOS #1(state bridge 移到 appleMain)同时合并时,git 能把这次对 bridge 的修改正确带到移动后的文件上;Mac 端的本地集成分支已经验证过。

Platforms can offer custom ranges (for example Oct 12 to Dec 31) without
reconstructing totals in UI. OverviewViewModel.loadRangeNow(start,
endExclusive) returns OverviewRangeUiState: daily stats for every day,
status distribution, completion periods, metrics compared with the
preceding period of the same length, and completed task titles. It uses
the same rules as the monthly projection (completions by completion
date, other states by due date). The Apple bridge exposes loadRange with
an error callback; ranges are limited to 1..3660 days.

@AritxOnly AritxOnly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed completedTaskTitles to use actual completion dates. Added coverage for late completion, no due date, completion before the range, and the exclusive end boundary.

Validation: combined PR #1–#4 checkout with both follow-up fixes; ./gradlew --offline -PlifiMode=stub :shared:macosArm64Test — 280 tests passed, 0 failures. Private Lifi mode and iOS framework linking were not rerun in this pass.

@AritxOnly
AritxOnly merged commit 4f8a706 into DeadlinerStudio:byos Nov 3, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants