From 264097e2533089494d0972c36dc53d83919ff98f Mon Sep 17 00:00:00 2001 From: Agus Zubiaga Date: Wed, 7 May 2025 01:41:04 -0300 Subject: [PATCH] agent: Use correct timezone for thread history separators (#30059) Turns out `naive_local` doesn't actually offset a `DateTime` to the local timezone before creating a `NaiveDate`. Release Notes: - agent: Use correct timezone for thread history separators --- crates/agent/src/thread_history.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/agent/src/thread_history.rs b/crates/agent/src/thread_history.rs index 8a348a5b7126ac86bd810d8831c9ea982ffc7263..87b67a60a5b9993636eb7ad839a03a159cf912e2 100644 --- a/crates/agent/src/thread_history.rs +++ b/crates/agent/src/thread_history.rs @@ -3,7 +3,7 @@ use std::ops::Range; use std::sync::Arc; use assistant_context_editor::SavedContextMetadata; -use chrono::{Datelike as _, NaiveDate, TimeDelta, Utc}; +use chrono::{Datelike as _, Local, NaiveDate, TimeDelta}; use editor::{Editor, EditorEvent}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ @@ -140,10 +140,14 @@ impl ThreadHistory { let bg_task = cx.background_spawn(async move { let mut bucket = None; - let today = Utc::now().naive_local().date(); + let today = Local::now().naive_local().date(); for (index, entry) in all_entries.iter().enumerate() { - let entry_date = entry.updated_at().naive_local().date(); + let entry_date = entry + .updated_at() + .with_timezone(&Local) + .naive_local() + .date(); let entry_bucket = TimeBucket::from_dates(today, entry_date); if Some(entry_bucket) != bucket { @@ -252,6 +256,14 @@ impl ThreadHistory { } } + fn list_item_count(&self) -> usize { + match &self.search_state { + SearchState::Empty => self.separated_items.len(), + SearchState::Searching { .. } => 0, + SearchState::Searched { matches, .. } => matches.len(), + } + } + fn search_produced_no_matches(&self) -> bool { match &self.search_state { SearchState::Empty => false, @@ -575,7 +587,7 @@ impl Render for ThreadHistory { uniform_list( cx.entity().clone(), "thread-history", - self.matched_count(), + self.list_item_count(), Self::list_items, ) .p_1()