mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
date: fix format literal for nanoseconds
This commit is contained in:
parent
8200d399e8
commit
12a43d6eb3
2 changed files with 10 additions and 3 deletions
|
@ -215,8 +215,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
eprintln!("date: invalid date ‘{}’", form);
|
eprintln!("date: invalid date ‘{}’", form);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f`
|
let form = form[1..].to_string();
|
||||||
let form = form[1..].replace("%N", "%f");
|
|
||||||
Format::Custom(form)
|
Format::Custom(form)
|
||||||
} else if let Some(fmt) = matches
|
} else if let Some(fmt) = matches
|
||||||
.values_of(OPT_ISO_8601)
|
.values_of(OPT_ISO_8601)
|
||||||
|
@ -302,7 +301,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
for date in dates {
|
for date in dates {
|
||||||
match date {
|
match date {
|
||||||
Ok(date) => {
|
Ok(date) => {
|
||||||
let formatted = date.format(format_string);
|
// GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f`
|
||||||
|
let format_string = &format_string.replace("%N", "%f");
|
||||||
|
let formatted = date.format(format_string).to_string().replace("%f", "%N");
|
||||||
println!("{}", formatted);
|
println!("{}", formatted);
|
||||||
}
|
}
|
||||||
Err((input, _err)) => {
|
Err((input, _err)) => {
|
||||||
|
|
|
@ -121,6 +121,12 @@ fn test_date_format_without_plus() {
|
||||||
.code_is(1);
|
.code_is(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_date_format_literal() {
|
||||||
|
new_ucmd!().arg("+%%s").succeeds().stdout_is("%s\n");
|
||||||
|
new_ucmd!().arg("+%%N").succeeds().stdout_is("%N\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
fn test_date_set_valid() {
|
fn test_date_set_valid() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue