date: don't ignore width prefix in %N format specifier (#12010)

* do not ignore %N if specified width is smaller than default width

* add test for issue #12001

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* cargo clippy

* truncate instead of popping in a loop

* Update format_modifiers.rs

* skip truncation if width is 0

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Devel08
2026-04-27 14:59:09 +02:00
committed by GitHub
co-authored by pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent 82590984a5
commit 5fa0aba94d
2 changed files with 13 additions and 0 deletions
+9
View File
@@ -3007,3 +3007,12 @@ fn test_korean_time_zone() {
.succeeds()
.stdout_is("2026-01-15 01:00:00 UTC\n");
}
// https://github.com/uutils/coreutils/issues/12001
// date: width prefix in %N format specifier is ignored ( %3N, %6N always output full 9 nanosecond digits) #12001
#[test]
fn test_nanoseconds_width_prefix_ignored_issue12001() {
let result = new_ucmd!().arg("+%3N").succeeds();
// compare to 4 because of \n
assert_eq!(result.stdout().len(), 4);
}