-
Notifications
You must be signed in to change notification settings - Fork 19
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
Clean slate with Winnow 2 #86
base: main
Are you sure you want to change the base?
Conversation
@tertsdiepraam I squashed your commits into a single commit, I hope you don't mind |
ff67b9e
to
85d7574
Compare
Looks cool! A few initial comments to send you in the right direction. One of the reasons for this rewrite is that chrono wasn't cutting it for adding all the items together. Instead we should add all the items together ourselves to really match GNU. It'll require a lot of experimentation, but it'll make the compatibility much better. I think most of the corner cases were around the ends of months. I believe GNU had some overflow behaviour there that chrono didn't. So I recommend first creating a custom datetime struct to manipulate and then mapping that to chrono. Squashing the commit is absolutely fine by the way. Thanks for continuing this! |
5516eed
to
9388e45
Compare
7592100
to
44a8141
Compare
44a8141
to
c76d675
Compare
Hi! I was looking at this again and I found an issue with how you're currently using
We need to find a way to construct the times such that this never happens. Just changing the order won't cut it because that can still lead to invalid states. |
e858dfd
to
417fde9
Compare
Hi Terts, I introduced a function to create dates from naive dates instead of using About the month behavior, if I understood correctly GNU gets the number of the days in the current month and adds it to the date, I implemented this behavior added your test and one more. |
417fde9
to
68498fa
Compare
@tertsdiepraam I was looking into the fuzzy testing. I added the code so it generates fuzzy dates with some sanity and caught some problems, I will look into them next. |
fuzz/fuzz_targets/parse_datetime.rs
Outdated
// Testing GNU compatibility by calling date and | ||
// comparing the inputs | ||
|
||
// let fmt = "%Y-%m-%d %H:%M:%S"; | ||
// let mut output: process::Output = std::process::Command::new("date") | ||
// .arg("-d") | ||
// .arg(s) | ||
// .arg(format!("+{fmt}")) | ||
// .output() | ||
// .expect("date command failed"); | ||
// io::stdout().write_all(&output.stdout).unwrap(); | ||
// io::stdout().write_all(&output.stderr).unwrap(); | ||
// output.stdout.pop(); // remove trailing \n | ||
// assert_eq!( | ||
// String::from_utf8(output.stdout).unwrap(), | ||
// d.format(fmt).to_string() | ||
// ); |
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.
I was testing something like this to determine its compatibility with GNU. The test run GNU date
in and compare the outputs
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.
We could definitely do that with fuzzing! We should still rely on regular tests as well though.
2389d91
to
025808c
Compare
src/lib.rs
Outdated
#[test] | ||
fn chrono_date() { | ||
const FMT: &str = "%Y-%m-%d %H:%M:%S"; | ||
let input = "262144-03-10 00:00:00"; | ||
|
||
// chrono rejects this specific date | ||
assert!(NaiveDate::from_ymd_opt(262144, 3, 10).is_none()); | ||
assert!(chrono::DateTime::parse_from_str(input, FMT).is_err()); | ||
// the parsing works, but hydration fails | ||
assert!(items::parse(&mut input.to_string().as_str()).is_ok()); | ||
assert!(parse_datetime(input).is_err()); | ||
// GNU date works | ||
assert_eq!(make_gnu_date(input, FMT), input); | ||
} |
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.
@tertsdiepraam I found a case where GNU accepts the date, we can parse it and chrono rejects it, more precisely chrono::NaiveDate::from_ymd_opt returns None for this date. I don't know what direction to take from there, chrono keeps getting in the way 😅 ideas? Maybe having a gnu-compatible datetime layer, but that will be a lot of work
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.
539a63f
to
307c159
Compare
307c159
to
a434820
Compare
sorry but some tests are failing:
and needs some rebasing |
I will rebase it But right now I have a problem with Chrono, I'm looking into alternatives like https://time-rs.github.io/book/how-to/create-dates.html |
Continuing the rewrite started by @tertsdiepraam #61
lib.rs
keep the same signaturelib.rs
too all they are passing@\d+
formatMMDDhhmm