-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add configurable timestamps to chat messages #10567
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
Draft
roomote
wants to merge
1
commit into
main
Choose a base branch
from
feature/issue-10539-add-timestamps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−1
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest" | ||
| import { formatTimestamp } from "../formatTimestamp" | ||
|
|
||
| describe("formatTimestamp", () => { | ||
| beforeEach(() => { | ||
| // Mock current date to 2026-01-09 14:30:00 | ||
| vi.useFakeTimers() | ||
| vi.setSystemTime(new Date("2026-01-09T14:30:00.000Z")) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| it("formats today's time in 24-hour format", () => { | ||
| // Same day at 10:15 | ||
| const timestamp = new Date("2026-01-09T10:15:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("10:15") | ||
| }) | ||
|
|
||
| it("pads single-digit hours and minutes", () => { | ||
| const timestamp = new Date("2026-01-09T09:05:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("09:05") | ||
| }) | ||
|
|
||
| it("includes date for messages from previous days", () => { | ||
| // Previous day | ||
| const timestamp = new Date("2026-01-08T14:34:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("Jan 8, 14:34") | ||
| }) | ||
|
|
||
| it("includes date for messages from previous months", () => { | ||
| // Previous month | ||
| const timestamp = new Date("2025-12-25T09:00:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("Dec 25, 09:00") | ||
| }) | ||
|
|
||
| it("includes date for messages from previous years", () => { | ||
| // Previous year | ||
| const timestamp = new Date("2025-06-15T18:45:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("Jun 15, 18:45") | ||
| }) | ||
|
|
||
| it("handles midnight correctly", () => { | ||
| const timestamp = new Date("2026-01-09T00:00:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("00:00") | ||
| }) | ||
|
|
||
| it("handles end of day correctly", () => { | ||
| const timestamp = new Date("2026-01-09T23:59:00.000Z").getTime() | ||
| expect(formatTimestamp(timestamp)).toBe("23:59") | ||
| }) | ||
|
|
||
| it("correctly abbreviates all months", () => { | ||
| const months = [ | ||
| { date: "2025-01-15", expected: "Jan" }, | ||
| { date: "2025-02-15", expected: "Feb" }, | ||
| { date: "2025-03-15", expected: "Mar" }, | ||
| { date: "2025-04-15", expected: "Apr" }, | ||
| { date: "2025-05-15", expected: "May" }, | ||
| { date: "2025-06-15", expected: "Jun" }, | ||
| { date: "2025-07-15", expected: "Jul" }, | ||
| { date: "2025-08-15", expected: "Aug" }, | ||
| { date: "2025-09-15", expected: "Sep" }, | ||
| { date: "2025-10-15", expected: "Oct" }, | ||
| { date: "2025-11-15", expected: "Nov" }, | ||
| { date: "2025-12-15", expected: "Dec" }, | ||
| ] | ||
|
|
||
| months.forEach(({ date, expected }) => { | ||
| const timestamp = new Date(`${date}T12:00:00.000Z`).getTime() | ||
| expect(formatTimestamp(timestamp)).toContain(expected) | ||
| }) | ||
| }) | ||
| }) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * Formats a Unix timestamp (in milliseconds) to a human-readable time string. | ||
| * | ||
| * Requirements from Issue #10539: | ||
| * - 24-hour format (14:34) | ||
| * - Full date for messages from previous days (e.g., "Jan 7, 14:34") | ||
| * - Text-size same as header row text | ||
| * | ||
| * @param ts - Unix timestamp in milliseconds | ||
| * @returns Formatted time string | ||
| */ | ||
| export function formatTimestamp(ts: number): string { | ||
| const date = new Date(ts) | ||
| const now = new Date() | ||
|
|
||
| // Check if the message is from today | ||
| const isToday = | ||
| date.getDate() === now.getDate() && | ||
| date.getMonth() === now.getMonth() && | ||
| date.getFullYear() === now.getFullYear() | ||
|
|
||
| // Format hours and minutes in 24-hour format | ||
| const hours = date.getHours().toString().padStart(2, "0") | ||
| const minutes = date.getMinutes().toString().padStart(2, "0") | ||
| const time = `${hours}:${minutes}` | ||
|
|
||
| if (isToday) { | ||
| // Just show time for today's messages | ||
| return time | ||
| } | ||
|
|
||
| // For older messages, show abbreviated month, day, and time | ||
| const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] | ||
| const month = months[date.getMonth()] | ||
| const day = date.getDate() | ||
|
|
||
| return `${month} ${day}, ${time}` | ||
| } |
Oops, something went wrong.
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.
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.
These tests are timezone-dependent and could fail in non-UTC environments. The mock time and test timestamps are specified in UTC, but
formatTimestampuses local time methods (getHours(),getDate()). In UTC+10, for example, 14:30 UTC becomes Jan 10, 00:30 local while 10:15 UTC becomes Jan 9, 20:15 local, making them different days and causing the "today's time" test to fail. Consider usinggetUTC*()methods in the implementation for consistent test behavior, or restructure tests to use timestamps that remain on the same calendar day across all timezones.Fix it with Roo Code or mention @roomote and request a fix.