Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/uu/date/src/format_modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ fn apply_modifiers(value: &str, parsed: &ParsedSpec<'_>) -> Result<String, Forma
padded.push_str(&result);
result = padded;
}
} else if specifier.ends_with('N') {
if effective_width <= get_default_width(specifier) && effective_width != 0 {
result.truncate(effective_width);
}
}

Ok(result)
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading