Repository navigation
Conversation
…t locale
Eight UI components handed the locale argument straight to the runtime
(toLocaleString / toLocaleDateString / toLocaleTimeString), so their output
was decided by the host OS date pattern instead of the active UI locale. This
is wrong even when both agree: a zh-CN app on a Chinese Windows renders
2024/11/21 where the unified layer renders 2024年11月21日.
format.ts already states that every date/time value must render through it
("so the UI locale controls presentation"), and lib/money.ts states "the OS
locale no longer participates" (issue helsome#86). Each call site now uses the
formatter whose options match the inline ones item by item
(formatDate / formatDateTime / formatMarketTime): no visible shape change, and
no epoch unit conversion is involved.
Add packages/ui/src/i18n/localeRendering.test.tsx (6 cases) as a guard, and one
matching case in DiscoverView.test.tsx. Pre-fix: localeRendering 0 pass / 6
fail and DiscoverView 12 pass / 1 fail. Post-fix: 6 pass / 0 fail and
13 pass / 0 fail. The three pre-existing suites in the affected directories
report 3/0, 6/0 and 5/0 both with and without the fix (A/B checked by restoring
the main bytes), so there is no behavioural regression.
Closes helsome#292
This was referenced Oct 6, 2026
helsome
requested changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
生产日期格式化方向合理,但本轮独立验证发现新增测试清理问题:精确 HEAD 的相关非隔离组合测试为6 pass / 27 fail / 1 error;--isolate 后仍33 pass / 1 error、exit 1,localeRendering 测试销毁 DOM 后仍有异步 React 更新。实际 main 对应既有四组测试26/0、exit 0。请在恢复全局 DOM 前完整卸载 root 并处理待执行更新,确保相关组合和全 UI 测试无未捕获错误。此外当前已合 #297,与 EvaluationSettingsTab.tsx 存在冲突,更新时保留错误翻译解析和本 PR 日期格式化两者。
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.
问题与修复
Closes #292
UI 包里有 8 处把区域参数直接交给
Date.prototype.toLocale*(toLocaleString()/toLocaleDateString()/toLocaleTimeString([], …)),输出因此由宿主 OS 的日期模式决定,与@finagent/i18n声明的契约相反(packages/i18n/src/format.ts:4-7:「Every money/percent/date/relative-time value must render through this layer so the UI locale controls presentation」;packages/ui/src/lib/money.ts:5-7:「the OS locale no longer participates」)。宿主语言与应用语言一致时同样出错 —— 应用语言
zh-CN、宿主中文 Windows 时内联调用走宿主yyyy/M/d模式,渲染成2024/11/21,而统一层对该语言给出2024年11月21日;宿主语言不同时连语言都会串。修复:每个调用点改用 options 逐项等价的统一层 formatter,一行改动 + 一行 import。
3a17eca6)components/primitives/DataFreshness.tsx:15new Date(updatedAtMs).toLocaleTimeString([], { hour:'2-digit', minute:'2-digit', second:'2-digit' })formatMarketTime(updatedAtMs)components/research/EvidenceList.tsx:26new Date(ref.fetchedAt).toLocaleTimeString()formatMarketTime(ref.fetchedAt)components/research/WhatChangedSection.tsx:53new Date(previousReport.generatedAt).toLocaleDateString()formatDate(previousReport.generatedAt)components/research/ResearchReportView.tsx:86new Date(report.generatedAt).toLocaleString()formatDateTime(report.generatedAt)components/settings/ConnectionCard.tsx:323new Date(lastCheck).toLocaleString()formatDateTime(lastCheck)components/settings/EvaluationSettingsTab.tsx:39new Date(updatedAt).toLocaleDateString(undefined, { year:'numeric', month:'short', day:'numeric' })formatDate(updatedAt)components/thesis/ThesisImpactList.tsx:40new Date(impact.evaluatedAt).toLocaleDateString()formatDate(impact.evaluatedAt)components/discover/DiscoverView.tsx:471new Date(run.createdAt).toLocaleString()formatDateTime(run.createdAt)选
formatDate/formatDateTime/formatMarketTime而非在各组件里补i18nCurrentLocale():8 处的 options 都能在统一层找到逐项等价实现(3/6/7 对应format.ts:114-122的formatDate;4/5/8 对应:124-134的formatDateTime;1/2 对应:136-144的formatMarketTime,其 docstring 正是 "Clock time only (market-data freshness lines)")。不新增任何 API,不改显示形状,也不涉及秒/毫秒换算(DataFreshness入参与ProviderHealth.lastCheck均为 epoch ms)。可复现测试报告
环境:Windows
10.0.26200.9457(x64)、Bun1.4.2、main3a17eca6。新增守卫
packages/ui/src/i18n/localeRendering.test.tsx(6 个用例,逐站点断言「应用语言决定输出」;宿主渲染结果与两个受支持语言都相同时会throw,避免空断言通过),并在packages/ui/src/components/discover/DiscoverView.test.tsx追加 1 个同型用例。修复前(把 8 个源文件还原为
3a17eca6的原始字节后重跑):修复后:
localeRendering6 pass / 0 fail;DiscoverView13 pass / 0 fail。受影响目录回归(
bun test --isolate,逐文件):components/primitives/DataFreshness.test.tsxcomponents/research/WhatChangedSection.test.tsxcomponents/evaluation/evaluation.test.tsxi18n/localeRendering.test.tsxcomponents/discover/DiscoverView.test.tsx其余校验:
bun run i18n:check⇒key parity: en-US 1487 keys ≡ zh-CN 1487 keys (0 issues)(零新增 key)。bun run typecheck(packages/ui⇒tsc --noEmit)exit 0。apps/electron的 e2e 套件(本机无法跑,见 issue e2e: 平台专属的 Electron 二进制路径与 POSIX shell 清理,让 harness 在 Windows 上无法运行 #223);全量bun test --isolate未跑,本次只跑改动工作区的聚焦套件。PR checks(.github/workflows/pr.yml)当前state=disabled_manually,新建 PR 不会产生 check run,因此以上均为本地等价命令结果,非 CI 结论。UI 变化
文本内容随应用语言变化,布局不变:
DataFreshness:Longbridge · Updated 09:20:00→ 应用语言为 en-US 时09:20:00 AMWhatChangedSection:2024/11/21→2024年11月21日(zh-CN)DiscoverView历史运行行:2023/11/14 22:13:20→2023年11月14日 22:13(zh-CN)范围
hour/minute/second与站点 6 的year/month/day都与原 options 逐项对应。components/today/TodayView.tsx:48(formatWhen的toLocaleDateString(undefined, { month:'short', day:'numeric' })):同一根因,但统一层没有该短日期形状的等价实现 ——formatDate会补年份(Nov 21→Nov 21, 2024),属可见形状变化,需单独决策。该形状的仓库既有先例是RuleCard.tsx:30的Intl.DateTimeFormat(i18nCurrentLocale(), { month:'short', day:'numeric' })。formatPrice的币种形状错误,其中仅 1 个toLocaleString调用点;本条不涉及金额。