-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): add formatRelative() for human-readable timestamps #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: p3-9/state/cursor-encoding
Are you sure you want to change the base?
Conversation
05957f2 to
cc258f2
Compare
63c1be5 to
53afbd2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc258f2c24
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
40d8c28 to
a527918
Compare
d1b8000 to
a213cf7
Compare
Greptile Summary
|
| Filename | Overview |
|---|---|
| packages/ui/src/index.ts | New formatRelative() function implementation with robust input handling and cascading time unit logic |
| packages/ui/src/tests/format-relative.test.ts | New comprehensive test suite covering all time ranges, input types, and edge cases for the formatRelative function |
Confidence score: 5/5
- This PR is safe to merge with minimal risk as it adds a self-contained utility function with comprehensive test coverage
- Score reflects the thorough implementation following TDD principles, robust error handling, and well-structured test cases
- No files require special attention as the code is well-tested and follows established patterns
Sequence Diagram
sequenceDiagram
participant User
participant formatRelative
participant Date
participant Math
User->>formatRelative: "Call with date input (Date|number|string)"
formatRelative->>formatRelative: "Convert input to timestamp"
alt "Input is Date object"
formatRelative->>Date: "getTime()"
Date-->>formatRelative: "timestamp"
else "Input is number"
formatRelative->>formatRelative: "Use as timestamp"
else "Input is string"
formatRelative->>Date: "parse(string)"
Date-->>formatRelative: "parsed timestamp"
end
formatRelative->>Date: "now()"
Date-->>formatRelative: "current timestamp"
formatRelative->>Math: "abs(now - timestamp)"
Math-->>formatRelative: "absolute difference"
formatRelative->>formatRelative: "Determine time unit and format"
alt "< 10 seconds"
formatRelative-->>User: "'just now'"
else "< 1 minute"
formatRelative-->>User: "'X seconds ago/in X seconds'"
else "< 1 hour"
formatRelative-->>User: "'X minutes ago/in X minutes'"
else "< 1 day"
formatRelative-->>User: "'X hours ago/in X hours'"
else "< 2 days"
formatRelative-->>User: "'yesterday/tomorrow'"
else "< 1 month"
formatRelative-->>User: "'X days ago/in X days'"
else "< 1 year"
formatRelative-->>User: "'X months ago/in X months'"
else "> 1 year"
formatRelative-->>User: "'X years ago/in X years'"
end
a213cf7 to
7f9c8de
Compare
a527918 to
acafeb4
Compare
|
Added explicit tests for invalid Date and non-finite timestamp inputs in formatRelative(). |
|
Fixed flakiness in formatRelative tests by freezing Date.now per test (avoids sub-millisecond drift in future-hour assertions). |
d23a2c1 to
9d8690a
Compare
acafeb4 to
542dd50
Compare
|
Resubmitted after restack; formatRelative already guards invalid Date/number inputs with Number.isFinite, so no additional changes needed here. |
Formats dates as relative time strings ("just now", "5 minutes ago",
"2 days ago"). Handles both past and future dates with appropriate
phrasing. Covers edge cases documented in SPEC.
Closes #48
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9d8690a to
48f18e3
Compare
542dd50 to
f814d80
Compare
|
Resubmitted after downstack updates; no new feedback beyond already-resolved formatRelative guard/test tweaks. |

Formats dates as relative time strings ("just now", "5 minutes ago",
"2 days ago"). Handles both past and future dates with appropriate
phrasing. Covers edge cases documented in SPEC.
Closes #48
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com