fix(viewer): handle multiple timestamp formats in days calculation#1219
Conversation
- Support milliseconds, microseconds, and seconds timestamp formats - Fixes incorrect days calculation when timestamps use different formats - Closes issue with 36500 days display error
|
Thanks for the PR — the direction is good, but the timestamp boundary logic needs adjustment. Counterexample: 1700000000000 (milliseconds) becomes 1700000000 (seconds), i.e. wrong unit downscaling. Please normalize to milliseconds as:
感谢提交!方向是对的,但时间戳区间判断还需要调整。 反例: 1700000000000 (毫秒)会被除成 1700000000 (秒),单位被错误降级。 请改为先统一到毫秒:
另外请补一个最小测试覆盖 seconds/milliseconds/microseconds,避免回归。谢谢! |
PR ReviewThis PR fixes the viewer timestamp normalization to handle three formats: seconds (< 1e12), milliseconds (1e12–1e15), and microseconds (>= 1e15). Previously, only seconds-to-milliseconds conversion was handled. However, there is a logic bug: Millisecond timestamps from ~2001 to ~2286 fall in the 1e12–1e15 range. The condition 此 PR 修复了 viewer 中时间戳归一化逻辑,支持秒、毫秒、微秒三种格式。但存在逻辑缺陷:毫秒级时间戳(2001–2286年)的范围正好是 1e12–1e15,与微秒判断区间重叠。例如
|
🔧 Suggested FixThe threshold between milliseconds and microseconds needs adjustment. A reasonable approach: if (e < 1e12) e *= 1000; // seconds → ms
else if (e >= 1e15) e = Math.floor(e / 1000); // microseconds → ms
// else: already milliseconds, no conversion neededThis avoids the ambiguous 1e12–1e15 range entirely by only converting values clearly above the millisecond range (>= 1e15 = year 33658 in ms). 🔧 修改建议毫秒和微秒的判断阈值需要调整。建议: if (e < 1e12) e *= 1000; // 秒 → 毫秒
else if (e >= 1e15) e = Math.floor(e / 1000); // 微秒 → 毫秒
// 否则:已经是毫秒,无需转换这样完全避开了 1e12–1e15 的模糊区间,只对明确大于毫秒范围的值(>= 1e15,即毫秒时间戳的 33658 年)做微秒转换。 |
Description
Changes
Modified
apps/memos-local-openclaw/src/viewer/html.ts:Related Issue
N/A (found during local testing)