Repository navigation
fix(#767): consolidate relative-time formatting into a single shared helper - #772
Merged
Merged
Conversation
- Extract canonical formatRelative() to web/src/lib/format-relative.ts - Math.floor throughout; locale date past 30 days on all four pages - Move relative.* i18n keys from topics namespace to common - Delete local copies from topics, prompts, insights, traffic pages - Add 14-case test suite following csv.test.ts pattern Intentional behaviour change: Insights and Traffic timestamps older than 30 days now render as a locale date instead of e.g. '412d ago'.
Contributor
|
The consolidation itself looks right — the floor-vs-round fix and the 30-day cliff are both pinned by tests, and moving the keys to Two small things before merge:
|
Contributor
Author
|
Both items addressed:
|
Contributor
|
Both fixes verified and merged — the codepoint check on the quotes was the right instinct. Four copies down to one, with the boundaries pinned by tests. Thanks! |
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.
Summary
Closes #767
Four pages (
topics,prompts,insights,traffic) each had their ownlocal implementation of the same relative-time helper. They had drifted into
three user-facing bugs:
Math.roundinstead ofMath.floor→ 90s showed as "2m ago", 45min as "1h ago"prompts/page.tsx'Just now'(capital J) instead of'just now'prompts/page.tsxinsights/page.tsx,traffic/page.tsxinsights/page.tsx,traffic/page.tsxChanges
web/src/lib/format-relative.ts— single canonical implementation.Math.floorthroughout, 30-day cliff falls back totoLocaleDateString(),i18n via
common.relative.*keys.web/src/lib/format-relative.test.ts— 14-case test suite coveringnull/undefined, sub-minute, the 90s floor-vs-round regression, the 45min
boundary, hour/day boundaries, the 30-day cliff, and the "412d ago"
regression.
web/messages/en.json—relative.*keys moved fromtopicsnamespaceto
commonso all four pages share them.topics/page.tsx— removed localformatRelative, uses shared helper.prompts/page.tsx— removed localformatRelative, uses shared helper.insights/page.tsx— removed localformatTimeAgo, uses shared helper.traffic/page.tsx— removed localtimeAgo, uses shared helper.Intentional behaviour change
Insights and Traffic previously showed timestamps older than 30 days as e.g.
412d ago. They now render as a locale date string (e.g.15 Jul 2025),matching the existing behaviour of Topics and Prompts.
Testing
pnpm tsc --noEmit— 0 errorspnpm lint— 0 errors, 7 warnings all pre-existingpnpm test— 112/112 passing