Skip to content

fix(viewer): handle multiple timestamp formats in days calculation#1219

Open
abakane1 wants to merge 1 commit intoMemTensor:mainfrom
abakane1:fix/timestamp-format-in-days-calculation
Open

fix(viewer): handle multiple timestamp formats in days calculation#1219
abakane1 wants to merge 1 commit intoMemTensor:mainfrom
abakane1:fix/timestamp-format-in-days-calculation

Conversation

@abakane1
Copy link

Description

  • Support milliseconds, microseconds, and seconds timestamp formats in days calculation
  • Fixes incorrect days calculation (showing 36500 days) when timestamps use different formats

Changes

Modified apps/memos-local-openclaw/src/viewer/html.ts:

// Before: only handled milliseconds
if(e<1e12) e*=1000;

// After: handles all timestamp formats
if (e < 1e15 && e >= 1e12) e = Math.floor(e / 1000);  // microseconds to milliseconds
else if (e < 1e12) e *= 1000;  // seconds to milliseconds

Related Issue

N/A (found during local testing)

- Support milliseconds, microseconds, and seconds timestamp formats
- Fixes incorrect days calculation when timestamps use different formats
- Closes issue with 36500 days display error
@hijzy
Copy link
Collaborator

hijzy commented Mar 16, 2026

Thanks for the PR — the direction is good, but the timestamp boundary logic needs adjustment.
Current logic treats 1e12 ~ 1e15 as microseconds and divides by 1000, which incorrectly affects millisecond timestamps.

Counterexample: 1700000000000 (milliseconds) becomes 1700000000 (seconds), i.e. wrong unit downscaling.

Please normalize to milliseconds as:

  • ts >= 1e15 : microseconds → Math.floor(ts / 1000)
  • 1e12 <= ts < 1e15 : milliseconds → keep as-is
  • ts < 1e12 : seconds → ts * 1000
    Please also add a minimal test covering seconds/milliseconds/microseconds to prevent regressions. Thanks!

感谢提交!方向是对的,但时间戳区间判断还需要调整。
你现在把 1e12 ~ 1e15 当作微秒并除以 1000,这会误伤毫秒时间戳。

反例: 1700000000000 (毫秒)会被除成 1700000000 (秒),单位被错误降级。

请改为先统一到毫秒:

  • ts >= 1e15 :微秒 → Math.floor(ts / 1000)
  • 1e12 <= ts < 1e15 :毫秒 → 保持不变
  • ts < 1e12 :秒 → ts * 1000

另外请补一个最小测试覆盖 seconds/milliseconds/microseconds,避免回归。谢谢!

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