Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Message hover date display (#1106)
Peter Chinmana993fd7514da
diff --git a/js/app/packages/block-channel/component/Message/MessageContainer.tsx b/js/app/packages/block-channel/component/Message/MessageContainer.tsxindex 82aa6d2d3d..950b2a2242 100644--- a/js/app/packages/block-channel/component/Message/MessageContainer.tsx+++ b/js/app/packages/block-channel/component/Message/MessageContainer.tsx@@ -525,6 +525,7 @@ export function MessageContainer(props: MessageProps) {isFirstMessage={isFirstMessage()}isLastMessage={isLastMessage()}isConsecutive={isConsecutive()}+ timestamp={message.created_at}shouldHover={contextMenuOpen() || topBarEmojiMenuOpen()}hoverActions={<ActionMenudiff --git a/js/app/packages/core/component/Message.tsx b/js/app/packages/core/component/Message.tsxindex e3a831579a..2ca067b48f 100644--- a/js/app/packages/core/component/Message.tsx+++ b/js/app/packages/core/component/Message.tsx@@ -35,6 +35,7 @@ export type MessageRootProps = {isFirstMessage: boolean;isLastMessage: boolean;isConsecutive?: boolean;+ timestamp?: string;hoverActions?: JSX.Element;shouldHover?: boolean;threadDepth?: number;@@ -128,8 +129,8 @@ const TopBar: Component<MessageTopBarProps> = (props) => {<span class="truncate">{local.tagLabel}</span></div></Show>- {/* Date */}- <Show when={local.timestamp}>+ {/* Date - hidden when hovering since it shows above hover actions */}+ <Show when={local.timestamp && !context.hover()}><div class="text-xs touch:mobile-width:text-sm text-ink-muted">{local.timestamp &&formatDate(new Date(local.timestamp).getTime() / 1000)}@@ -333,7 +334,7 @@ const Root: Component<MessageRootProps> = (props) => {</BozzyBracket><Show when={props.hoverActions && !isTouchDevice()}><div- class="absolute right-2 -top-2 border border-edge bg-panel"+ class="absolute right-0 -top-2 flex flex-col items-end z-tool-tip"classList={{block: hover() || !!props.shouldHover,hidden: !(hover() || !!props.shouldHover),@@ -341,7 +342,14 @@ const Root: Component<MessageRootProps> = (props) => {onMouseEnter={() => setHover(true)}onMouseLeave={() => setHover(false)}>- {props.hoverActions}+ <Show when={props.timestamp}>+ <div class="absolute top-0 translate-y-[-100%] bg-panel pl-2 pt-2 text-xs text-ink-muted font-mono mb-0.5 select-text cursor-default">+ {formatDate(new Date(props.timestamp!).getTime() / 1000, {+ showTime: true,+ })}+ </div>+ </Show>+ <div class="border border-edge bg-panel">{props.hoverActions}</div></div></Show><Show when={props.isLastInThread}>diff --git a/js/app/packages/core/tests/date.test.ts b/js/app/packages/core/tests/date.test.tsindex b7caec81e7..2ff8bcda1f 100644--- a/js/app/packages/core/tests/date.test.ts+++ b/js/app/packages/core/tests/date.test.ts@@ -23,56 +23,75 @@ describe('Date Utilities (core/utils/date.ts)', () => {it('should format time for today', () => {// Today at 8:15 AM UTCconst todayMorning = epochTime('2025-06-14T08:15:00.000Z');- expect(formatDate(todayMorning, mockNowEpochSeconds, 'UTC')).toBe(- '8:15 AM'- );+ expect(+ formatDate(todayMorning, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ })+ ).toBe('8:15 AM');});it('should format "Yesterday at {time}" for yesterday (UTC day boundary)', () => {// Yesterday at 11:00 PM UTC (June 13)const yesterdayEvening = epochTime('2025-06-13T23:00:00.000Z');- expect(formatDate(yesterdayEvening, mockNowEpochSeconds, 'UTC')).toBe(- 'Yesterday at 11:00 PM'- );+ expect(+ formatDate(yesterdayEvening, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ })+ ).toBe('Yesterday at 11:00 PM');});it('should handle edge case at UTC midnight boundary', () => {// Reference time: June 14, 2:15 PM UTC// Yesterday at 11:59 PM UTC (June 13) - just before midnightconst justBeforeMidnight = epochTime('2025-06-13T23:59:59.000Z');- expect(formatDate(justBeforeMidnight, mockNowEpochSeconds, 'UTC')).toBe(- 'Yesterday at 11:59 PM'- );+ expect(+ formatDate(justBeforeMidnight, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ })+ ).toBe('Yesterday at 11:59 PM');});it('should handle same day even with less than 24 hour difference', () => {// Reference time: June 14, 2:15 PM UTC// Same day at 1:00 AM UTC (13.25 hours earlier, but same UTC day)const earlyToday = epochTime('2025-06-14T01:00:00.000Z');- expect(formatDate(earlyToday, mockNowEpochSeconds, 'UTC')).toBe(- '1:00 AM'- );+ expect(+ formatDate(earlyToday, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ })+ ).toBe('1:00 AM');});it('should handle yesterday even with more than 24 hour difference', () => {// Reference time: June 14, 2:15 PM UTC// Yesterday at 1:00 AM UTC (37.25 hours earlier, but still "yesterday")const yesterdayEarly = epochTime('2025-06-13T01:00:00.000Z');- expect(formatDate(yesterdayEarly, mockNowEpochSeconds, 'UTC')).toBe(- 'Yesterday at 1:00 AM'- );+ expect(+ formatDate(yesterdayEarly, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ })+ ).toBe('Yesterday at 1:00 AM');});it('should format weekday for recent days (2-6 days ago)', () => {// June 12 (2 days ago) - should show weekdayconst twoDaysAgo = epochTime('2025-06-12T15:00:00.000Z');- expect(formatDate(twoDaysAgo, mockNowEpochSeconds)).toBe('Thursday');+ expect(formatDate(twoDaysAgo, { epochNow: mockNowEpochSeconds })).toBe(+ 'Thursday'+ );});it('should format date for older dates (more than 7 days)', () => {// June 1, 2025 (13 days ago)const oldDate = epochTime('2025-06-01T12:00:00.000Z');- expect(formatDate(oldDate, mockNowEpochSeconds)).toBe('06/01/25');+ expect(formatDate(oldDate, { epochNow: mockNowEpochSeconds })).toBe(+ '06/01/25'+ );});it('should handle timezone-aware day boundaries', () => {@@ -82,14 +101,20 @@ describe('Date Utilities (core/utils/date.ts)', () => {// In Eastern timezone, this should be "Today"const lateEastern = epochTime('2025-06-15T03:30:00.000Z');expect(- formatDate(lateEastern, mockNowEpochSeconds, 'America/New_York')+ formatDate(lateEastern, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'America/New_York',+ })).toBe('11:30 PM');// In UTC timezone, this should be "Tomorrow" (but we'll get weekday since it's >1 day diff)// Let's test with a timestamp that's same day in Eastern but different day in UTCconst easternToday = epochTime('2025-06-14T23:30:00.000Z');expect(- formatDate(easternToday, mockNowEpochSeconds, 'America/New_York')+ formatDate(easternToday, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'America/New_York',+ })).toBe('7:30 PM');});@@ -97,16 +122,158 @@ describe('Date Utilities (core/utils/date.ts)', () => {// This test ensures our fallback values prevent month=-1 or day=0 edge cases// We can't easily mock formatToParts to fail, but we can test with extreme datesconst extremeDate = epochTime('1900-01-01T00:00:00.000Z');- const result = formatDate(- extremeDate,- mockNowEpochSeconds,- 'America/New_York'- );+ const result = formatDate(extremeDate, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'America/New_York',+ });// Should not throw and should return a reasonable date format (not crash due to invalid Date)expect(typeof result).toBe('string');// The exact date format may vary by timezone, but it should be a valid date stringexpect(result).toMatch(/^\d{2}\/\d{2}\/\d{2}$/);});++ describe('showTime parameter', () => {+ it('should include time for weekday format when showTime is true', () => {+ // June 12 (2 days ago) - should show "Thursday at {time}"+ const twoDaysAgo = epochTime('2025-06-12T15:30:00.000Z');+ expect(+ formatDate(twoDaysAgo, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: true,+ })+ ).toBe('Thursday at 3:30 PM');+ });++ it('should not include time for weekday format when showTime is false', () => {+ // June 12 (2 days ago) - should show only "Thursday"+ const twoDaysAgo = epochTime('2025-06-12T15:30:00.000Z');+ expect(+ formatDate(twoDaysAgo, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: false,+ })+ ).toBe('Thursday');+ });++ it('should not include time for weekday format when showTime is undefined', () => {+ // June 12 (2 days ago) - should show only "Thursday" (default behavior)+ const twoDaysAgo = epochTime('2025-06-12T15:30:00.000Z');+ expect(+ formatDate(twoDaysAgo, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: undefined,+ })+ ).toBe('Thursday');+ });++ it('should include time for date format when showTime is true', () => {+ // June 1, 2025 (13 days ago) - should show date with time+ const oldDate = epochTime('2025-06-01T16:45:00.000Z');+ expect(+ formatDate(oldDate, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: true,+ })+ ).toBe('06/01/25 at 4:45 PM');+ });++ it('should not include time for date format when showTime is false', () => {+ // June 1, 2025 (13 days ago) - should show only date+ const oldDate = epochTime('2025-06-01T16:45:00.000Z');+ expect(+ formatDate(oldDate, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: false,+ })+ ).toBe('06/01/25');+ });++ it('should not include time for date format when showTime is undefined', () => {+ // June 1, 2025 (13 days ago) - should show only date (default behavior)+ const oldDate = epochTime('2025-06-01T16:45:00.000Z');+ expect(+ formatDate(oldDate, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: undefined,+ })+ ).toBe('06/01/25');+ });++ it('should not affect "today" format regardless of showTime (already shows time)', () => {+ // Today at 8:15 AM UTC+ const todayMorning = epochTime('2025-06-14T08:15:00.000Z');+ expect(+ formatDate(todayMorning, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: true,+ })+ ).toBe('8:15 AM');+ expect(+ formatDate(todayMorning, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: false,+ })+ ).toBe('8:15 AM');+ });++ it('should not affect "yesterday" format regardless of showTime (already shows time)', () => {+ // Yesterday at 11:00 PM UTC (June 13)+ const yesterdayEvening = epochTime('2025-06-13T23:00:00.000Z');+ expect(+ formatDate(yesterdayEvening, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: true,+ })+ ).toBe('Yesterday at 11:00 PM');+ expect(+ formatDate(yesterdayEvening, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: false,+ })+ ).toBe('Yesterday at 11:00 PM');+ });++ it('should handle showTime with timezone-aware formatting', () => {+ // June 12, 2025 at 11:30 PM Eastern (3:30 AM UTC June 13)+ const testDate = epochTime('2025-06-13T03:30:00.000Z');+ expect(+ formatDate(testDate, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'America/New_York',+ showTime: true,+ })+ ).toBe('Thursday at 11:30 PM');+ });++ it('should handle showTime for dates at the 7-day boundary', () => {+ // Exactly 7 days ago - should use date format+ const sevenDaysAgo = epochTime('2025-06-07T14:15:00.000Z');+ expect(+ formatDate(sevenDaysAgo, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: true,+ })+ ).toBe('06/07/25 at 2:15 PM');+ expect(+ formatDate(sevenDaysAgo, {+ epochNow: mockNowEpochSeconds,+ timeZone: 'UTC',+ showTime: false,+ })+ ).toBe('06/07/25');+ });+ });});});diff --git a/js/app/packages/core/util/date.ts b/js/app/packages/core/util/date.tsindex c0acdac4da..b21ff8f790 100644--- a/js/app/packages/core/util/date.ts+++ b/js/app/packages/core/util/date.ts@@ -1,16 +1,21 @@+export interface FormatDateOptions {+ /** Unix timestamp in seconds. An optional reference date. */+ epochNow?: number;+ /** IANA timezone string (e.g., 'America/New_York', 'UTC'). Defaults to system timezone. */+ timeZone?: string;+ /** If true, always include time in the output (e.g., 'Thursday at 4:53 PM' instead of 'Thursday'). */+ showTime?: boolean;+}+/*** Formats epoch date (unix timestamp seconds) to a human readable date.* @param epochDate - Unix timestamp in seconds. The date to format.- * @param epochNow - Unix timestamp in seconds. An optional reference date.- * @param timeZone - IANA timezone string (e.g., 'America/New_York', 'UTC'). Defaults to system timezone.+ * @param options - Optional formatting options.* @returns Formatted date string. Like '4:53 PM' for same local day or, 'Yesterday at 8:10 AM' for* single day offsets, 'Thursday' for a day within the week and '01/23/2025' for dates outside the week.*/-export const formatDate = (- epochDate: number,- epochNow?: number,- timeZone?: string-) => {+export const formatDate = (epochDate: number, options?: FormatDateOptions) => {+ const { epochNow, timeZone, showTime } = options ?? {};// handle computation in different timezonesconst getDatePartsInTimezone = (date: Date, tz?: string) => {if (tz) {@@ -75,18 +80,20 @@ export const formatDate = (const diffMs = now.getTime() - inputDate.getTime();const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));if (days < 7) {- return inputDate.toLocaleDateString(undefined, {+ const weekday = inputDate.toLocaleDateString(undefined, {weekday: 'long',timeZone,});+ return showTime ? `${weekday} at ${time}` : weekday;}- return inputDate.toLocaleDateString(undefined, {+ const date = inputDate.toLocaleDateString(undefined, {month: '2-digit',day: '2-digit',year: '2-digit',timeZone,});+ return showTime ? `${date} at ${time}` : date;};/**