mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
stat: fix precision when rendering mtime (%Y)
Support precision when rendering the time of last data modification with `stat`. For example, after this commit $ stat --printf='%.1Y\n' f 1668645806.7 Previously, the precision in the format specification was ignored. This is implemented with a custom renderer because GNU `stat` seems to truncate the number as opposed to rounding the number as would happen when using `format!` with a specified number of digits of precision. Fixes #3233
This commit is contained in:
parent
cef9a2b960
commit
1d0dcb5962
2 changed files with 88 additions and 2 deletions
|
@ -184,6 +184,17 @@ fn test_char() {
|
|||
];
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
||||
eprintln!("{expected_stdout}");
|
||||
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_printf_mtime_precision() {
|
||||
let args = ["-c", "%.0Y %.1Y %.2Y %.3Y %.4Y", "/dev/pts/ptmx"];
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
||||
eprintln!("{expected_stdout}");
|
||||
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue