From 9ef33fa90fcea06af246d4972e103c84da269069 Mon Sep 17 00:00:00 2001 From: lashman Date: Sat, 7 Mar 2026 22:35:25 +0200 Subject: [PATCH] Fix CLI/GTK history timestamp format mismatch CLI now stores Unix seconds (matching GTK) so age-based history pruning works correctly. Human-readable formatting applied only at display time in cmd_history and cmd_undo. --- pixstrip-cli/src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pixstrip-cli/src/main.rs b/pixstrip-cli/src/main.rs index 6217e10..38b332e 100644 --- a/pixstrip-cli/src/main.rs +++ b/pixstrip-cli/src/main.rs @@ -503,7 +503,7 @@ fn cmd_history() { println!( "{}. [{}] {} -> {} ({}/{} succeeded, {})", i + 1, - entry.timestamp, + format_timestamp(&entry.timestamp), entry.input_dir, entry.output_dir, entry.succeeded, @@ -541,7 +541,7 @@ fn cmd_undo(count: usize) { if entry.output_files.is_empty() { println!( "Batch from {} has no recorded output files - cannot undo", - entry.timestamp + format_timestamp(&entry.timestamp) ); failed_entries.push(entry); continue; @@ -1041,14 +1041,20 @@ fn format_duration(ms: u64) -> String { } fn chrono_timestamp() -> String { - // Human-readable timestamp without chrono dependency - let now = std::time::SystemTime::now(); - let secs = now + // Store as Unix seconds string (must match GTK format for pruning compatibility) + std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() - .as_secs(); + .as_secs() + .to_string() +} + +/// Format a Unix-seconds timestamp string as human-readable "YYYY-MM-DD HH:MM:SS" +fn format_timestamp(ts: &str) -> String { + let Ok(secs) = ts.parse::() else { + return ts.to_string(); // already human-readable or unparseable - return as-is + }; - // Convert to date/time components let days = secs / 86400; let time_secs = secs % 86400; let hours = time_secs / 3600;