@@ -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<Utc>) -> 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()
@@ -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)