Skip to content

Conversation

@galligan
Copy link
Contributor

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

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Adds formatRelative() function to packages/ui/src/index.ts for human-readable timestamp formatting ("just now", "5 minutes ago", "tomorrow")
  • Introduces comprehensive test suite in packages/ui/src/__tests__/format-relative.test.ts covering multiple input types, edge cases, and future/past date handling

Important Files Changed

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
Loading

@galligan galligan changed the base branch from p3-9/state/cursor-encoding to graphite-base/72 January 23, 2026 21:24
@galligan galligan force-pushed the p3-10/ui/format-relative branch from a213cf7 to 7f9c8de Compare January 23, 2026 21:25
@galligan galligan changed the base branch from graphite-base/72 to p3-9/state/cursor-encoding January 23, 2026 21:25
@galligan
Copy link
Contributor Author

Added explicit tests for invalid Date and non-finite timestamp inputs in formatRelative().

@galligan
Copy link
Contributor Author

Fixed flakiness in formatRelative tests by freezing Date.now per test (avoids sub-millisecond drift in future-hour assertions).

@galligan galligan changed the base branch from p3-9/state/cursor-encoding to graphite-base/72 January 24, 2026 02:42
@galligan galligan force-pushed the p3-10/ui/format-relative branch from d23a2c1 to 9d8690a Compare January 24, 2026 02:43
@galligan galligan changed the base branch from graphite-base/72 to p3-9/state/cursor-encoding January 24, 2026 02:43
@galligan
Copy link
Contributor Author

Resubmitted after restack; formatRelative already guards invalid Date/number inputs with Number.isFinite, so no additional changes needed here.

galligan and others added 3 commits January 23, 2026 22:45
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>
@galligan galligan changed the base branch from p3-9/state/cursor-encoding to graphite-base/72 January 24, 2026 03:49
@galligan galligan force-pushed the p3-10/ui/format-relative branch from 9d8690a to 48f18e3 Compare January 24, 2026 03:50
@galligan galligan changed the base branch from graphite-base/72 to p3-9/state/cursor-encoding January 24, 2026 03:50
@galligan
Copy link
Contributor Author

Resubmitted after downstack updates; no new feedback beyond already-resolved formatRelative guard/test tweaks.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants