From 4315744abbb1783f3b81ddceccc9cdbf9d2eba93 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 13 Aug 2025 13:23:32 -0400 Subject: [PATCH] Improve Memory sorting --- src/memories.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/memories.rs b/src/memories.rs index 5d3189b..fb0248d 100644 --- a/src/memories.rs +++ b/src/memories.rs @@ -237,11 +237,14 @@ pub async fn list_memories( }; let now = if let Some(tz) = client_timezone { + debug!("Client timezone: {:?}", tz); Utc::now().with_timezone(&tz).date_naive() } else { Local::now().date_naive() }; + debug!("Now: {:?}", now); + let base = Path::new(&app_state.base_path); let mut memories_with_dates: Vec<(MemoryItem, NaiveDate)> = Vec::new(); @@ -282,8 +285,21 @@ pub async fn list_memories( } } - // Sort by day of the month - memories_with_dates.sort_by_key(|k| k.1.day()); + // Sort by day of the month and time (using the created timestamp) + memories_with_dates.sort_by(|a, b| { + let day_comparison = a.1.day().cmp(&b.1.day()); + + if day_comparison == std::cmp::Ordering::Equal { + match (a.0.created, b.0.created) { + (Some(a_time), Some(b_time)) => a_time.cmp(&b_time), + (Some(_), None) => std::cmp::Ordering::Less, + (None, Some(_)) => std::cmp::Ordering::Greater, + (None, None) => std::cmp::Ordering::Equal, + } + } else { + day_comparison + } + }); let items: Vec = memories_with_dates.into_iter().map(|(m, _)| m).collect();