diff --git a/src/find/matchers/printf.rs b/src/find/matchers/printf.rs index c371734..3924618 100644 --- a/src/find/matchers/printf.rs +++ b/src/find/matchers/printf.rs @@ -50,7 +50,11 @@ impl TimeFormat { .to_string() } TimeFormat::Strftime(format) => { - DateTime::::from(time).format(format).to_string() + // Handle a special case + let custom_format = format.replace("%+", "%Y-%m-%d+%H:%M:%S%.f0"); + DateTime::::from(time) + .format(&custom_format) + .to_string() } }; diff --git a/tests/find_cmd_tests.rs b/tests/find_cmd_tests.rs index ad2a34f..a40e754 100644 --- a/tests/find_cmd_tests.rs +++ b/tests/find_cmd_tests.rs @@ -10,6 +10,7 @@ use assert_cmd::Command; use predicates::prelude::*; +use regex::Regex; use serial_test::serial; use std::fs::{self, File}; use std::io::{Read, Write}; @@ -367,6 +368,27 @@ fn find_printf() { ./test_data/simple/subdir/ABBBC subdir/ABBBC f\n", ))); + let output = Command::cargo_bin("find") + .expect("found binary") + .args(["a", "-printf", " %A+"]) + .assert() + .success() + .get_output() + .stdout + .clone(); + + let output_str = String::from_utf8(output).expect("Invalid UTF-8 in output"); + + println!("Actual output: '{}'", output_str.trim()); + + let re = Regex::new(r"^\d{4}-\d{2}-\d{2}\+\d{2}:\d{2}:\d{2}\.\d{9}0$") + .expect("Failed to compile regex"); + + assert!( + re.is_match(&output_str.trim()), + "Output did not match expected timestamp format" + ); + Command::cargo_bin("find") .expect("found binary") .args([