From fdb769c132a613136542de4cbcfe1b10b6488018 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Wed, 18 Mar 2026 17:50:30 +0100 Subject: [PATCH] sidebar: Fix date formatting (#51851) Previously we were not showing days Release Notes: - N/A --- crates/agent_ui/src/threads_archive_view.rs | 49 ++++++++++++--------- crates/sidebar/src/sidebar.rs | 25 ++--------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/crates/agent_ui/src/threads_archive_view.rs b/crates/agent_ui/src/threads_archive_view.rs index 9b4f9d215f6c572c64a8f548d3bd6955a9ff38ec..4cdbe0dd272c6659b7a534afc0ef560eea93ca3b 100644 --- a/crates/agent_ui/src/threads_archive_view.rs +++ b/crates/agent_ui/src/threads_archive_view.rs @@ -7,7 +7,7 @@ use crate::{ use acp_thread::AgentSessionInfo; use agent::ThreadStore; use agent_client_protocol as acp; -use chrono::{Datelike as _, Local, NaiveDate, TimeDelta, Utc}; +use chrono::{DateTime, Datelike as _, Local, NaiveDate, TimeDelta, Utc}; use editor::Editor; use fs::Fs; use gpui::{ @@ -453,26 +453,10 @@ impl ThreadsArchiveView { let focus_handle = self.focus_handle.clone(); let highlight_positions = highlight_positions.clone(); - let timestamp = session.created_at.or(session.updated_at).map(|entry_time| { - let now = Utc::now(); - let duration = now.signed_duration_since(entry_time); - - let minutes = duration.num_minutes(); - let hours = duration.num_hours(); - let days = duration.num_days(); - let weeks = days / 7; - let months = days / 30; - - if minutes < 60 { - format!("{}m", minutes.max(1)) - } else if hours < 24 { - format!("{}h", hours) - } else if weeks < 4 { - format!("{}w", weeks.max(1)) - } else { - format!("{}mo", months.max(1)) - } - }); + let timestamp = session + .created_at + .or(session.updated_at) + .map(format_history_entry_timestamp); let id = SharedString::from(format!("archive-entry-{}", ix)); @@ -739,6 +723,29 @@ impl ThreadsArchiveView { } } +pub fn format_history_entry_timestamp(entry_time: DateTime) -> String { + let now = Utc::now(); + let duration = now.signed_duration_since(entry_time); + + let minutes = duration.num_minutes(); + let hours = duration.num_hours(); + let days = duration.num_days(); + let weeks = days / 7; + let months = days / 30; + + if minutes < 60 { + format!("{}m", minutes.max(1)) + } else if hours < 24 { + format!("{}h", hours.max(1)) + } else if days < 7 { + format!("{}d", days.max(1)) + } else if weeks < 4 { + format!("{}w", weeks.max(1)) + } else { + format!("{}mo", months.max(1)) + } +} + impl Focusable for ThreadsArchiveView { fn focus_handle(&self, _cx: &App) -> FocusHandle { self.focus_handle.clone() diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 4ffa1518f0442fbd1c8192bd87aa6419ad2a8497..5624ae3169122dab98e76ee0b2ff3ce056d73a17 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -3,7 +3,9 @@ use action_log::DiffStats; use agent::ThreadStore; use agent_client_protocol::{self as acp}; use agent_ui::thread_metadata_store::{ThreadMetadata, ThreadMetadataStore}; -use agent_ui::threads_archive_view::{ThreadsArchiveView, ThreadsArchiveViewEvent}; +use agent_ui::threads_archive_view::{ + ThreadsArchiveView, ThreadsArchiveViewEvent, format_history_entry_timestamp, +}; use agent_ui::{Agent, AgentPanel, AgentPanelEvent, NewThread, RemoveSelectedThread}; use chrono::Utc; use editor::Editor; @@ -2127,26 +2129,7 @@ impl Sidebar { .session_info .created_at .or(thread.session_info.updated_at) - .map(|entry_time| { - let now = Utc::now(); - let duration = now.signed_duration_since(entry_time); - - let minutes = duration.num_minutes(); - let hours = duration.num_hours(); - let days = duration.num_days(); - let weeks = days / 7; - let months = days / 30; - - if minutes < 60 { - format!("{}m", minutes.max(1)) - } else if hours < 24 { - format!("{}h", hours) - } else if weeks < 4 { - format!("{}w", weeks.max(1)) - } else { - format!("{}mo", months.max(1)) - } - }); + .map(format_history_entry_timestamp); ThreadItem::new(id, title) .icon(thread.icon)