-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
date: Catch format string that is not supported by chrono #4244
date: Catch format string that is not supported by chrono #4244
Conversation
Interesting! I have two questions.
|
src/uu/date/src/date.rs
Outdated
@@ -244,6 +244,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { | |||
Ok(date) => { | |||
// GNU `date` uses `%N` for nano seconds, however crate::chrono uses `%f` | |||
let format_string = &format_string.replace("%N", "%f"); | |||
if format_string.contains("%#z") { | |||
return Err(USimpleError::new(1, "do not use '%#z' is is undefined")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another typo here. I think we can also be a bit more descriptive than the chrono error.
This isn't caught by the change I made in #4240 because that catches issues where a string isn't successfully parsed, here it is successfully parsed but one of the format items is explicitly forbidden.
The expected behaviour according to GNU date is for
However, currently chrono doesn't support the |
Co-authored-by: Sylvestre Ledru <[email protected]>
Fails with:
|
GNU testsuite comparison:
|
Can this be merged now? I don't think those test failures are related to this change |
yeah, sorry, i added a comment. |
Attempting to use
%#z
with chrono gets a panic: https://github.com/chronotope/chrono/blob/378efb157d674c01761f538d4450705c2b1766a4/src/format/mod.rs#L683This catches the format string and returns an error instead.
Fixes: #4538