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.
This commit is contained in:
2026-03-07 22:35:25 +02:00
parent e65ed866eb
commit 9ef33fa90f

View File

@@ -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::<u64>() 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;