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:
@@ -503,7 +503,7 @@ fn cmd_history() {
|
|||||||
println!(
|
println!(
|
||||||
"{}. [{}] {} -> {} ({}/{} succeeded, {})",
|
"{}. [{}] {} -> {} ({}/{} succeeded, {})",
|
||||||
i + 1,
|
i + 1,
|
||||||
entry.timestamp,
|
format_timestamp(&entry.timestamp),
|
||||||
entry.input_dir,
|
entry.input_dir,
|
||||||
entry.output_dir,
|
entry.output_dir,
|
||||||
entry.succeeded,
|
entry.succeeded,
|
||||||
@@ -541,7 +541,7 @@ fn cmd_undo(count: usize) {
|
|||||||
if entry.output_files.is_empty() {
|
if entry.output_files.is_empty() {
|
||||||
println!(
|
println!(
|
||||||
"Batch from {} has no recorded output files - cannot undo",
|
"Batch from {} has no recorded output files - cannot undo",
|
||||||
entry.timestamp
|
format_timestamp(&entry.timestamp)
|
||||||
);
|
);
|
||||||
failed_entries.push(entry);
|
failed_entries.push(entry);
|
||||||
continue;
|
continue;
|
||||||
@@ -1041,14 +1041,20 @@ fn format_duration(ms: u64) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn chrono_timestamp() -> String {
|
fn chrono_timestamp() -> String {
|
||||||
// Human-readable timestamp without chrono dependency
|
// Store as Unix seconds string (must match GTK format for pruning compatibility)
|
||||||
let now = std::time::SystemTime::now();
|
std::time::SystemTime::now()
|
||||||
let secs = now
|
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.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 days = secs / 86400;
|
||||||
let time_secs = secs % 86400;
|
let time_secs = secs % 86400;
|
||||||
let hours = time_secs / 3600;
|
let hours = time_secs / 3600;
|
||||||
|
|||||||
Reference in New Issue
Block a user