diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index bc50a8a2c..76b245923 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -404,9 +404,8 @@ fn make_format_string(settings: &Settings) -> &str { /// If it fails, return a tuple of the `String` along with its `ParseError`. fn parse_date + Clone>( s: S, -) -> Result, (String, chrono::format::ParseError)> { - // TODO: The GNU date command can parse a wide variety of inputs. - s.as_ref().parse().map_err(|e| (s.as_ref().into(), e)) +) -> Result, (String, parse_datetime::ParseDateTimeError)> { + parse_datetime::parse_datetime(s.as_ref()).map_err(|e| (s.as_ref().into(), e)) } #[cfg(not(any(unix, windows)))] diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index def3fa8af..f45b81cb5 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -409,3 +409,20 @@ fn test_date_overflow() { .no_stdout() .stderr_contains("invalid date"); } + +#[test] +fn test_date_parse_from_format() { + let (at, mut ucmd) = at_and_ucmd!(); + const FILE: &str = "file-with-dates"; + + at.write( + FILE, + "2023-03-27 08:30:00\n\ + 2023-04-01 12:00:00\n\ + 2023-04-15 18:30:00", + ); + ucmd.arg("-f") + .arg(at.plus(FILE)) + .arg("+%Y-%m-%d %H:%M:%S") + .succeeds(); +}