S039: relative dates, 12/24-hour clock, date settings

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-18 19:46:15 -06:00
commit f5ba5fdebe
10 changed files with 194 additions and 28 deletions

View file

@ -13,6 +13,7 @@ Status: planned → done (later plans update their rows when they ship a feature
| Playlist sort in the music folder (m3u, m3u8, pls, xspf, wpl order; folder and shared Playlists folder) | done | S008 | tunal-core::playlist, tunal |
| Tabs, split view, editable breadcrumb path bar, back / forward / up, places sidebar | planned | S010 | tunal |
| Copy path, properties, Open, Open with | planned | S012 | tunal |
| Relative dates ("5 minutes ago", "Yesterday, 3:42 PM") turning into date and time, 12/24-hour clock, both set in Settings | done | S039 | tunal |
| Settings dialog and context menus the user can edit (add, remove, reorder) | planned | S013 | tunal |
| In-app drag and drop (Move / Copy / Link / Cancel menu) | planned | S014 | tunal |
| `.directory` files: folder icon, display name, view settings, editable | planned | S015 | tunal-dirmeta |

View file

@ -10,10 +10,10 @@ The user can't read the current `21 Oct 19:38` stamps and wants relative dates t
CLAUDE.md §3; D-037; `crates/tunal/src/folder/format.rs` (`date`), `crates/tunal/src/config.rs`, `crates/tunal/ui/dialogs/settings.slint`, S013's PROGRESS entry.
## Steps
- [ ] `format::date` with a style: **Relative** (default): `Just now` (< 1 min), `5 minutes ago`, `3 hours ago` (today), `Yesterday, 3:42 PM`, weekday within 7 days (`Monday, 3:42 PM`), then `Nov 3, 3:42 PM` this year and `Nov 3, 2024` before; **Absolute**: always date + time. Clock **12-hour** (default) or **24-hour**. Properties dialog uses absolute full date + time in the chosen clock.
- [ ] Config keys in `settings.toml` (`date_style`, `clock`) and a "Dates and times" group in Settings > General (radio/segmented, live update of open views without reload).
- [ ] Relative stamps refresh: one timer per window ticking once a minute only while a visible row shows a relative stamp under 1 hour; stopped otherwise (no idle repaint).
- [ ] FEATURES.md row; PROGRESS entry, INDEX line, commit `S039: …`
- [x] `format::date` with a style: **Relative** (default): `Just now` (< 1 min), `5 minutes ago`, `3 hours ago` (today), `Yesterday, 3:42 PM`, weekday within 7 days (`Monday, 3:42 PM`), then `Nov 3, 3:42 PM` this year and `Nov 3, 2024` before; **Absolute**: always date + time. Clock **12-hour** (default) or **24-hour**. Properties dialog uses absolute full date + time in the chosen clock.
- [x] Config keys in `settings.toml` (`date_style`, `clock`) and a "Dates and times" group in Settings > General (radio/segmented, live update of open views without reload).
- [x] Relative stamps refresh: one timer per window ticking once a minute only while a visible row shows a relative stamp under 1 hour; stopped otherwise (no idle repaint).
- [x] FEATURES.md row; PROGRESS entry, INDEX line, commit `S039: …`
## End criteria
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --check` pass.

View file

@ -15,7 +15,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
- [x] [S004 — Base animated controls](02%20App%20skeleton/S004-base-controls.md) · Opus high
- [x] [S005 — Menus, dialogs and toasts](02%20App%20skeleton/S005-menus-dialogs.md) · Opus high
- [x] [S038 — Expressive restyle (shapes, ripples, rounded surfaces)](02%20App%20skeleton/S038-expressive-restyle.md) · Opus high (runs after S013, before S014)
- [ ] [S039 — Relative dates, 12/24-hour clock and more settings](03%20File%20browsing/S039-relative-dates-settings.md) · Sonnet medium
- [x] [S039 — Relative dates, 12/24-hour clock and more settings](03%20File%20browsing/S039-relative-dates-settings.md) · Sonnet medium
## 03 File browsing

View file

@ -99,6 +99,25 @@ pub enum Motion {
Full,
}
/// How modified dates read: "3 hours ago" turning into a date, or always date and time.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DateStyle {
#[default]
Relative,
Absolute,
}
/// 12-hour (`3:42 PM`) or 24-hour (`15:42`) clock.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum Clock {
#[default]
#[serde(rename = "12h")]
H12,
#[serde(rename = "24h")]
H24,
}
/// `settings.toml`. Later plans add their fields here.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
@ -114,6 +133,8 @@ pub struct Settings {
pub sort_descending: bool,
pub group: Group,
pub motion: Motion,
pub date_style: DateStyle,
pub clock: Clock,
}
impl Default for Settings {
@ -128,6 +149,8 @@ impl Default for Settings {
sort_descending: false,
group: Group::None,
motion: Motion::System,
date_style: DateStyle::Relative,
clock: Clock::H12,
}
}
}

View file

@ -1,7 +1,10 @@
//! Size and date text for the details columns.
use std::sync::atomic::{AtomicU8, Ordering};
use std::time::SystemTime;
pub use crate::config::{Clock, DateStyle};
/// `512 B`, `1.4 KiB`, `23 MiB`: one decimal below 10, none above.
pub fn size(bytes: u64) -> String {
const UNITS: [&str; 6] = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB"];
@ -21,22 +24,97 @@ pub fn size(bytes: u64) -> String {
}
}
/// `Today 14:03`, `Yesterday 09:10`, `12 Mar 14:03` this year, `12 Mar 2024` before.
static DATE_STYLE: AtomicU8 = AtomicU8::new(0);
static CLOCK: AtomicU8 = AtomicU8::new(0);
/// Sets how every date is written from now on; views redraw their rows to show it.
pub fn set_dates(style: DateStyle, clock: Clock) {
DATE_STYLE.store(style as u8, Ordering::Relaxed);
CLOCK.store(clock as u8, Ordering::Relaxed);
}
fn style() -> DateStyle {
if DATE_STYLE.load(Ordering::Relaxed) == DateStyle::Absolute as u8 {
DateStyle::Absolute
} else {
DateStyle::Relative
}
}
fn clock() -> Clock {
if CLOCK.load(Ordering::Relaxed) == Clock::H24 as u8 {
Clock::H24
} else {
Clock::H12
}
}
/// `3:42 PM` or `15:42`.
fn time_of(when: &jiff::Zoned) -> String {
match clock() {
Clock::H12 => when.strftime("%-I:%M %p").to_string(),
Clock::H24 => when.strftime("%H:%M").to_string(),
}
}
/// True when `date` would show minutes ("5 minutes ago") or "Just now", which go stale.
pub fn is_fresh(time: SystemTime) -> bool {
style() == DateStyle::Relative
&& time
.elapsed()
.is_ok_and(|age| age < std::time::Duration::from_secs(3600))
}
/// Relative style: `Just now`, `5 minutes ago`, `3 hours ago`, `Yesterday, 3:42 PM`,
/// `Monday, 3:42 PM` within a week, `Nov 3, 3:42 PM` this year, `Nov 3, 2024` before.
/// Absolute style: date and time (`Nov 3, 2025, 3:42 PM`).
pub fn date(time: SystemTime) -> String {
let Ok(ts) = jiff::Timestamp::try_from(time) else {
return String::new();
};
let tz = jiff::tz::TimeZone::system();
let when = ts.to_zoned(tz.clone());
let today = jiff::Timestamp::now().to_zoned(tz).date();
let now = jiff::Timestamp::now();
if style() == DateStyle::Absolute {
return format!("{}, {}", when.strftime("%b %-d, %Y"), time_of(&when));
}
let secs = now.as_second() - ts.as_second();
if (0..60).contains(&secs) || secs < 0 {
return "Just now".into();
}
let today = now.to_zoned(tz).date();
let day = when.date();
if day == today {
when.strftime("Today %H:%M").to_string()
} else if today.yesterday().is_ok_and(|y| y == day) {
when.strftime("Yesterday %H:%M").to_string()
let (n, unit) = if secs < 3600 {
(secs / 60, "minute")
} else {
(secs / 3600, "hour")
};
let plural = if n == 1 { "" } else { "s" };
return format!("{n} {unit}{plural} ago");
}
let days = (today - day).get_days();
if days == 1 {
format!("Yesterday, {}", time_of(&when))
} else if days < 7 {
format!("{}, {}", when.strftime("%A"), time_of(&when))
} else if day.year() == today.year() {
when.strftime("%-d %b %H:%M").to_string()
format!("{}, {}", when.strftime("%b %-d"), time_of(&when))
} else {
when.strftime("%-d %b %Y").to_string()
when.strftime("%b %-d, %Y").to_string()
}
}
/// Full date with seconds, always absolute, in the chosen clock (the Properties dialog).
pub fn long_date(time: SystemTime) -> String {
jiff::Timestamp::try_from(time)
.map(|ts| {
let when = ts.to_zoned(jiff::tz::TimeZone::system());
let clock = match self::clock() {
Clock::H12 => when.strftime("%-I:%M:%S %p"),
Clock::H24 => when.strftime("%H:%M:%S"),
};
format!("{} {clock}", when.strftime("%a %-d %b %Y,"))
})
.unwrap_or_default()
}

View file

@ -585,6 +585,19 @@ impl FolderModel {
}
}
/// Redraws the rows (a date setting changed, or a minute passed).
pub fn redraw_dates(&self) {
self.notify.reset();
}
/// True when a row shows a date that changes within the hour.
pub fn has_fresh_dates(&self) -> bool {
let s = self.state.borrow();
s.items
.iter()
.any(|i| i.entry.mtime.is_some_and(format::is_fresh))
}
/// True when everything selected (or under the cursor) is a folder.
pub fn selection_is_dir(&self) -> bool {
let s = self.state.borrow();

View file

@ -5,7 +5,7 @@ use std::fs;
use std::ops::ControlFlow;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, Instant};
use tunal_core::{Entry, Kind, Locations, Uri};
@ -208,16 +208,19 @@ fn describe(locations: &Locations, uris: &[Uri], entries: &[(Uri, Entry)], faile
.push(("Link to".into(), tunal_core::display_name(target)));
}
if let Some(time) = entry.mtime {
info.rows.push(("Modified".into(), long_date(time)));
info.rows
.push(("Modified".into(), crate::folder::format::long_date(time)));
}
if let Some(path) = uri.to_path()
&& let Ok(meta) = fs::symlink_metadata(&path)
{
if let Ok(time) = meta.accessed() {
info.rows.push(("Accessed".into(), long_date(time)));
info.rows
.push(("Accessed".into(), crate::folder::format::long_date(time)));
}
if let Ok(time) = meta.created() {
info.rows.push(("Created".into(), long_date(time)));
info.rows
.push(("Created".into(), crate::folder::format::long_date(time)));
}
}
let permissions = locations
@ -263,16 +266,6 @@ fn describe(locations: &Locations, uris: &[Uri], entries: &[(Uri, Entry)], faile
info
}
fn long_date(time: SystemTime) -> String {
jiff::Timestamp::try_from(time)
.map(|ts| {
ts.to_zoned(jiff::tz::TimeZone::system())
.strftime("%a %-d %b %Y, %H:%M:%S")
.to_string()
})
.unwrap_or_default()
}
/// `drwxr-xr-x` style text without the type letter: `rwxr-xr-x`, with `s`/`t` for the
/// special bits.
fn mode_text(mode: u32) -> String {

View file

@ -7,7 +7,8 @@ use std::rc::{Rc, Weak};
use slint::{ComponentHandle, ModelRc, VecModel};
use crate::actions::{Action, Actions};
use crate::config::{self, Group, Motion, Sort, View};
use crate::config::{self, Clock, DateStyle, Group, Motion, Sort, View};
use crate::folder::format;
use crate::menus::{Context, SEPARATOR};
use crate::shell::Shell;
use crate::{EditRow, MainWindow, SettingsData, theme_bridge};
@ -21,6 +22,9 @@ pub struct SettingsUi {
context: Cell<usize>,
/// The ids of that menu: what the editor edits.
ids: RefCell<Vec<String>>,
/// Once a minute: redraws "5 minutes ago" stamps; a tick with none under an hour old
/// repaints nothing.
tick: slint::Timer,
}
impl SettingsUi {
@ -32,9 +36,26 @@ impl SettingsUi {
actions: actions.clone(),
context: Cell::new(0),
ids: RefCell::new(Vec::new()),
tick: slint::Timer::default(),
});
theme_bridge::set_motion(ui, config::load::<config::Settings>("settings").motion);
let cfg = config::load::<config::Settings>("settings");
theme_bridge::set_motion(ui, cfg.motion);
format::set_dates(cfg.date_style, cfg.clock);
settings.bind(ui);
let shell = Rc::downgrade(shell);
settings.tick.start(
slint::TimerMode::Repeated,
std::time::Duration::from_secs(60),
move || {
if let Some(shell) = shell.upgrade() {
for pane in shell.panes() {
if pane.model.has_fresh_dates() {
pane.model.redraw_dates();
}
}
}
},
);
settings
}
@ -48,6 +69,8 @@ impl SettingsUi {
sort_descending: cfg.sort_descending,
group: cfg.group as i32,
motion: cfg.motion as i32,
date_style: cfg.date_style as i32,
clock: cfg.clock as i32,
}
}
@ -78,15 +101,20 @@ impl SettingsUi {
[data.group.clamp(0, 3) as usize];
cfg.motion =
[Motion::System, Motion::Reduce, Motion::Full][data.motion.clamp(0, 2) as usize];
cfg.date_style =
[DateStyle::Relative, DateStyle::Absolute][data.date_style.clamp(0, 1) as usize];
cfg.clock = [Clock::H12, Clock::H24][data.clock.clamp(0, 1) as usize];
// The window's own sidebar state is saved with the session, not by this dialog.
if let Some(ui) = self.ui.upgrade() {
cfg.show_sidebar = ui.get_show_sidebar();
theme_bridge::set_motion(&ui, cfg.motion);
}
config::store("settings", &cfg);
format::set_dates(cfg.date_style, cfg.clock);
if let Some(shell) = self.shell.upgrade() {
for pane in shell.panes() {
pane.model.apply_config(&cfg);
pane.model.redraw_dates();
}
}
}

View file

@ -21,6 +21,10 @@ export struct SettingsData {
sort-descending: bool,
group: int,
motion: int,
// 0 relative, 1 absolute.
date-style: int,
// 0 12-hour, 1 24-hour.
clock: int,
}
// One choice out of a few, as a row of chips.
@ -192,6 +196,26 @@ export component SettingsDialog inherits Dialog {
}
}
ChoiceSetting {
title: "Dates";
names: ["Relative", "Date and time"];
current: root.data.date-style;
picked(i) => {
root.data.date-style = i;
root.changed(root.data);
}
}
ChoiceSetting {
title: "Clock";
names: ["12-hour", "24-hour"];
current: root.data.clock;
picked(i) => {
root.data.clock = i;
root.changed(root.data);
}
}
Setting {
title: "Restore tabs";
hint: "Open the tabs of the last session at start.";

View file

@ -145,5 +145,11 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Verified: workspace build, clippy -D warnings, fmt --check; `cargo run -p tunal-net --example ssh_smoke` with HOME overridden: Include file listed, first-match/negation resolution, plain + hashed + port + revoked + ca entries, accept then Match, write under ~/.ssh refused, sample ~/.ssh unchanged.
- Not done: no real ~/.ssh read; `Match` conditions not evaluated (block skipped); `%h`-style tokens only for HostName; no host-key algorithm negotiation preference.
## S039 — Relative dates and clock
- Done: `format::date` follows `DateStyle` (Relative default: Just now, N minutes/hours ago, Yesterday/weekday + time, `Nov 3, 3:42 PM`, `Nov 3, 2024`; Absolute: `Nov 3, 2025, 3:42 PM`) and `Clock` (12h default, 24h) kept in process-wide atomics (`format::set_dates`). `format::long_date` (Properties) always absolute, with seconds, in the chosen clock. `settings.toml` keys `date_style` (`relative|absolute`), `clock` (`12h|24h`); Settings > General has "Dates" and "Clock" chips; a change redraws every pane at once (`FolderModel::redraw_dates`).
- Tick: one 60 s repeating timer in `SettingsUi` redraws panes that hold an entry under 1 hour old; other ticks repaint nothing (timer itself keeps running).
- Verified: workspace build, clippy -D warnings, fmt --check; screenshot of a scratch folder: 2 hours ago, 5 minutes ago, Just now, Friday, Nov 9, Nov 18 2025, Yesterday, all 12-hour.
- Not done: 24-hour and Absolute not screenshotted; timer not stopped when nothing is fresh; "visible row" check covers all rows of a pane; conflict dialog dates use the same setting but were not looked at.
## Later
-