Repository navigation
fix(ui): NewsView 按 epoch 秒渲染新闻时效,不再恒显示「N 年前」 - #234
Merged
Merged
Conversation
`relativeTime()` 用 `Date.now() - timestamp` 直接相减,而 `NewsItem.timestamp` 的单位是 epoch 秒(core/market-data.ts:10-11), 于是 diff 被放大 1000 倍,`minutes/hours/days/months` 四级分支全部跳过, 恒定落到 `yearsAgo` —— 5 分钟前的新闻也显示「57y ago」, 连 `diff < 0` 的「just now」兜底都永不触发。 按能力层 `research-news.ts:57` 的既有写法先换算再相减。 新增 `NewsView.test.tsx`(3 例,渲染真实组件 + createSyncI18n): 修复前 0 pass / 3 fail(三条均渲染成同一句 "57y ago") → 修复后 3 pass / 0 fail。
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
本轮独立源码审查及精确 HEAD focused 3/0 通过。最新main累计组合完整测试1959 pass / 7 skip / 0 fail,全workspace typecheck、i18n通过,secret扫描零命中。仅按本PR声明范围验收,不把离线回归当真实模型/生产API验收。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与修复
NewsView的relativeTime()(packages/ui/src/components/workspace/NewsView.tsx:10)用Date.now() - timestamp直接相减,但NewsItem.timestamp的单位是 epoch 秒。依据是仓库自己的两处自述契约:
packages/core/src/market-data.ts:10-11:「Timestamps are epoch SECONDS unless noted otherwise, matching the existing core convention (Quote.timestamp,Kline.timestamp,NewsItem.timestamp).」packages/shared/src/capabilities/manifests/research-news.ts:40marketTime: latest.timestamp * 1000、:57new Date(item.timestamp * 1000)。于是
diff被放大 1000 倍,minutes → hours → days → months四级分支全部跳过,恒定落到yearsAgo;连if (diff < 0) return justNow的兜底也永不触发。修复:按能力层的既有写法先换算再相减。
Closes #233
可复现测试报告
环境:Windows 11 / Bun 1.4.2;本地基线 = 上游 main
ba5dcdfd31b162f5edb8b908f7f099a560389326(2026-09-24T11:05:17Z),工作树已按 main 字节对齐。新增回归用例
packages/ui/src/components/workspace/NewsView.test.tsx(渲染真实NewsView组件 +createSyncI18n,3 例):bun test ./packages/ui/src/components/workspace/NewsView.test.tsx修复前三条用例收到的渲染文本完全相同,都是
"Apple ships a thingA summary57y ago":NewsItem.timestamp输入now - 5*60(5 分钟前)57y ago5m ago5m agonow - 3*86400(3 天前)57y ago3d ago3d agonow + 30(略超前,时钟漂移)57y agojust nowjust now硬门禁:
bun run typecheck—— core / i18n / shared / ui / electron 五个工作区全部 exit 0。bun test packages/ui --isolate—— 324 pass / 0 fail(对齐 main 的本机基线 321 pass / 0 fail + 本轮新增 3 例)。未运行的测试:未跑
bun test --isolate全量(本机 6 核 / 8GB 负载下超时抖动明显,且本 PR 只动packages/ui);apps/electrone2e 未跑,本机沙箱无法 spawncmd.exe(已知环境限制)。UI 变化
新闻列表右侧的相对时间文案由恒定的「57y ago」变为真实时效(
5m ago/3d ago/hours/just now等)。无布局、样式或 DOM 结构变化;无新增依赖;未改动任何公共导出面。