Skip to content

Commit

Permalink
manage the special case 'find %A+'
Browse files Browse the repository at this point in the history
Closes: #451
  • Loading branch information
sylvestre committed Sep 21, 2024
1 parent 5cfac37 commit 2c0dd4c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/find/matchers/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ impl TimeFormat {
.to_string()
}
TimeFormat::Strftime(format) => {
DateTime::<Local>::from(time).format(format).to_string()
// Handle a special case
let custom_format = format.replace("%+", "%Y-%m-%d+%H:%M:%S%.f0");
DateTime::<Local>::from(time)
.format(&custom_format)
.to_string()
}
};

Expand Down
22 changes: 22 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 2c0dd4c

Please sign in to comment.