Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Grouping by date has future, last week, last month and last year

gelenmedyaf29f3e8c3225
diff --git a/crates/rf-app/src/folder_view.rs b/crates/rf-app/src/folder_view.rs
index 9199c97b..b72b3779 100644
--- a/crates/rf-app/src/folder_view.rs
+++ b/crates/rf-app/src/folder_view.rs
@@ -169,20 +169,30 @@ fn item_tip_card(
v_flex().min_w(px(220.)).max_w(px(360.)).py(px(2.)).gap(px(8.)).child(title).child(div().h(px(1.)).bg(p.divider)).child(table).into_any_element()
}
-/// "Today / yesterday / this week ..." of a time.
+/// "Today / yesterday / this week / last week ..." of a time, newest first.
+///
+/// (Discussion 1095: "when grouping by date, there are no these groups: in the future, last week, last month, last year", as
+/// Directory Opus has them; File Explorer has last week and last month too.)
fn relative_day(ms: i64, now: chrono::DateTime<chrono::Local>) -> (u32, String) {
use chrono::{Datelike, TimeZone};
let Some(t) = chrono::Local.timestamp_millis_opt(ms).single().filter(|_| ms > 0) else {
- return (6, "Bilinmiyor".into());
+ return (10, "Bilinmiyor".into());
};
- let days = (now.date_naive() - t.date_naive()).num_days();
+ let (day, today) = (t.date_naive(), now.date_naive());
+ let days = (today - day).num_days();
+ let last_week = (today - chrono::Duration::days(7)).iso_week();
+ let (last_month_year, last_month) = if now.month() == 1 { (now.year() - 1, 12) } else { (now.year(), now.month() - 1) };
match days {
- d if d <= 0 => (0, "Bugün".into()),
- 1 => (1, "Dün".into()),
- d if d < 7 && t.iso_week() == now.iso_week() => (2, "Bu hafta".into()),
- _ if t.year() == now.year() && t.month() == now.month() => (3, "Bu ay".into()),
- _ if t.year() == now.year() => (4, "Bu yıl".into()),
- _ => (5, "Daha eski".into()),
+ d if d < 0 => (0, "Gelecekte".into()),
+ 0 => (1, "Bugün".into()),
+ 1 => (2, "Dün".into()),
+ d if d < 7 && day.iso_week() == today.iso_week() => (3, "Bu hafta".into()),
+ d if d < 14 && day.iso_week() == last_week => (4, "Geçen hafta".into()),
+ _ if t.year() == now.year() && t.month() == now.month() => (5, "Bu ay".into()),
+ _ if t.year() == last_month_year && t.month() == last_month => (6, "Geçen ay".into()),
+ _ if t.year() == now.year() => (7, "Bu yıl".into()),
+ _ if t.year() == now.year() - 1 => (8, "Geçen yıl".into()),
+ _ => (9, "Daha eski".into()),
}
}
@@ -9527,3 +9537,36 @@ mod autoscroll_tests {
assert_eq!(super::drag_edge_speed(50., 100.), 0.);
}
}
+
+#[cfg(test)]
+mod date_group_tests {
+ use chrono::TimeZone;
+
+ fn at(y: i32, m: u32, d: u32) -> chrono::DateTime<chrono::Local> {
+ chrono::Local.with_ymd_and_hms(y, m, d, 12, 0, 0).single().unwrap()
+ }
+
+ /// Discussion 1095: the future, last week, last month and last year have groups of their own, in time order.
+ #[test]
+ fn dates_fall_into_their_groups_newest_first() {
+ // Saturday 5 December 2026
+ let now = at(2026, 12, 5);
+ let group = |t: chrono::DateTime<chrono::Local>| super::relative_day(t.timestamp_millis(), now).1;
+ assert_eq!(group(at(2026, 12, 9)), "Gelecekte");
+ assert_eq!(group(at(2026, 12, 5)), "Bugün");
+ assert_eq!(group(at(2026, 12, 4)), "Dün");
+ assert_eq!(group(at(2026, 12, 1)), "Bu hafta", "Tuesday of the same week");
+ assert_eq!(group(at(2026, 11, 26)), "Geçen hafta");
+ assert_eq!(group(at(2026, 11, 20)), "Geçen ay");
+ assert_eq!(group(at(2026, 6, 1)), "Bu yıl");
+ assert_eq!(group(at(2025, 3, 1)), "Geçen yıl");
+ assert_eq!(group(at(2020, 3, 1)), "Daha eski");
+ // a January: last month is December of the year before
+ assert_eq!(super::relative_day(at(2026, 12, 20).timestamp_millis(), at(2027, 1, 20)).1, "Geçen ay");
+ let order: Vec<u32> = [at(2026, 12, 9), at(2026, 12, 5), at(2026, 12, 4), at(2026, 12, 1), at(2026, 11, 26), at(2026, 11, 20), at(2026, 6, 1), at(2025, 3, 1), at(2020, 3, 1)]
+ .iter()
+ .map(|t| super::relative_day(t.timestamp_millis(), now).0)
+ .collect();
+ assert!(order.windows(2).all(|w| w[0] < w[1]), "{order:?}");
+ }
+}
diff --git a/crates/rf-app/src/i18n_en.rs b/crates/rf-app/src/i18n_en.rs
index 24b73752..b3f49840 100644
--- a/crates/rf-app/src/i18n_en.rs
+++ b/crates/rf-app/src/i18n_en.rs
@@ -114,6 +114,10 @@ pub const EN: &[(&str, &str)] = &[
("Bugün", "Today"),
("Dün", "Yesterday"),
("Bu hafta", "This week"),
+ ("Gelecekte", "In the future"),
+ ("Geçen hafta", "Last week"),
+ ("Geçen ay", "Last month"),
+ ("Geçen yıl", "Last year"),
("Bu ay", "This month"),
("Bu yıl", "This year"),
("Daha eski", "Older"),