Skip to content

bug: four copies of the relative-time helper disagree about the same timestamp #767

Closed

Description

@gkhngyk

Description

"Last run" timestamps are rendered by four separate copies of the same helper, under three different names, and they have drifted apart:

Where Name Under a minute Rounding Past 30 days
topics/page.tsx#L57 formatRelative(iso, t) t('relative.justNow') Math.floor locale date
prompts/page.tsx#L274 formatRelative(iso?) Just now Math.round locale date
insights/page.tsx#L1731 formatTimeAgo(date: Date) just now Math.floor Xd ago
traffic/page.tsx#L203 timeAgo(dateStr) just now Math.floor Xd ago

Three of those differences are visible to the user:

  • Rounding. A run 90 seconds ago reads 2m ago on Prompts and 1m ago on Topics. At 45 minutes Prompts says 1h ago while the other three still say 45m ago.
  • Casing. Just now on Prompts, just now everywhere else.
  • The 30-day cliff. Topics and Prompts hand off to a locale date; Insights and Traffic keep counting days indefinitely, so a year-old timestamp reads 412d ago.

Only the Topics copy goes through i18n.

Steps to reproduce

  1. Note a brand's last-run time on the Topics page.
  2. Open the Prompts page and find the same brand's last run.
  3. Compare them at a point where the rounding differs — 90 seconds, or 45 minutes.

Expected behavior

One timestamp renders one way, wherever it appears.

Actual behavior

The same instant produces different strings depending on which page you are on.

Deployment mode

Cloud (ansvisor.com)

Environment

Not environment-specific — these are pure functions.

Notes for whoever picks this up

The Topics copy is the one to keep. It uses Math.floor, hands off to a locale date past 30 days, and reads its strings from topics.relative.* in web/messages/en.json.

  • New home: web/src/lib/format-relative.ts, with web/src/lib/format-relative.test.ts beside it. web/src/lib/csv.test.ts is the pattern to follow for both.
  • The relative.* keys currently live under the topics namespace. Moving them to common — which already exists — lets all four call sites share them.
  • The Insights copy takes a Date; the other three take an ISO string. Pick one signature and adjust that call site rather than supporting both.
  • Prompts' copy returns — for a missing value; keep that, the table depends on it.
  • Adopting the Topics behaviour changes what Insights and Traffic show past 30 days. That is the intent, but call it out in the PR so it doesn't read as an accident.

Tests worth having: the sub-minute boundary, floor vs round at 90 seconds, the hour and day boundaries, the 30-day cliff, and a null/undefined input.

Activity

  1. added
    bug
    good first issue
    help wanted
    on Aug 21, 2026
  2. Maqbool61 commented on Aug 21, 2026

    @Maqbool61
    Contributor

    Working on this issue.

  3. added a commit that references this issue on Aug 22, 2026
  4. Maqbool61 commented on Aug 23, 2026

    @Maqbool61
    Contributor

    Forgot to add "Closes" that's why issue is still open can you close it? @gkhngyk

  5. gkhngyk commented on Aug 25, 2026

    @gkhngyk
    ContributorAuthor

    Delivered by #772. Verified on main: one implementation in web/src/lib/format-relative.ts with tests beside it, all four call sites (topics, prompts, insights, traffic) importing it, no copies left behind, and the strings moved to common.relative.* so every page goes through i18n. Thanks @Maqbool61 — the missing Closes line was all that kept this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions