-
Notifications
You must be signed in to change notification settings - Fork 34
Support weekdays in parse_datetime #34
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
Conversation
|
Just to note, we (at least I) already see updates for all uutils crates when I log on to github. Mentions don't really help, we'll look at the PR without them too 🙂 |
|
So should i wait for #25 to be merged and then refactor? |
|
Hmm yeah I'm not really sure what the best course of action is. The situation is a bit unfortunate. I guess it depends on a few things:
The first question is kinda tough. I think a basic Maybe another approach is to transition to I'm really just explaining my thoughts here. I'm not yet really sure what the best approach is. What do you think? |
How about waiting until next week and see the progress of #25. If nothing happens i can rewrite this pr first to use nom and check the pr. |
|
Sounds good to me! |
55badc9 to
de2ef37
Compare
|
@tertsdiepraam thanks for reviewing, but i am currently rewriting it to use nom. |
|
I converted it to draft, sorry. |
|
No worries! Looking forward to the nom version! |
2cfe2fd to
fe29267
Compare
fe29267 to
f072913
Compare
|
@tertsdiepraam it should be ready to review now. |
tertsdiepraam
left a comment
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.
Interesting! I quite like how that's looking. It's definitely a nice way to start using nom!
0c86935 to
1ab0e0d
Compare
a4b5423 to
46bfd1c
Compare
|
@tertsdiepraam i did all the requests accept one, i am not sure what "m" means, but it does not seem to be monday. I just tested all letters from a to z with |
|
@tertsdiepraam i believe i found the reference source code, apparently "WEDNES" is also valid. https://github.com/coreutils/gnulib/blob/master/lib/parse-datetime.y#L1032 |
46bfd1c to
82b2294
Compare
|
@tertsdiepraam apparently one letter is military time table, i will create another issue. https://github.com/coreutils/gnulib/blob/master/lib/parse-datetime.y#L1155 |
|
Here is the issue: #39 |
82b2294 to
93be2f5
Compare
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.
Nice work! I have just two more comments for things that should not be fixed in this PR and one question.
It's great that parse_datetime is receiving some proper attention from you. Thanks!
|
|
||
| // parse weekday | ||
| if let Some(weekday) = parse_weekday::parse_weekday(s.as_ref()) { | ||
| let mut beginning_of_day = date |
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.
Oh I see what the trouble was now. I forgot we needed 00:00 on the time. I'm not sure what the best way to do that is. This looks ok, but it would be great if chrono had some nice method for this, but I can't find any 😄
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 dit not find anything either :(
src/lib.rs
Outdated
| beginning_of_day += Duration::days(1); | ||
| } | ||
|
|
||
| if let Ok(dt) = naive_dt_to_fixed_offset(date, beginning_of_day.naive_local()) { |
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.
Does using From<DateTime<FixedOffset>> for DateTime<Local> work here or is the naive_local necessary?
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 seems it works, thanks.
| #[test] | ||
| fn test_weekday() { | ||
| // add some constant hours and minutes and seconds to check its reset | ||
| let date = Local.with_ymd_and_hms(2023, 02, 28, 10, 12, 3).unwrap(); |
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.
Oww, I really want parse_datetime_at_date to not take Local anymore. But we'll get to that in another PR. Looks great for now!
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 am not sure how to best not use local but agreed.
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.
Yeah, parse_datetime_at_date should just be generic over the timezone. And then it can be called with Utc, Local or FixedOffset. Like I said though, definitely out of scope for this PR.
93be2f5 to
ea4b709
Compare
|
@tertsdiepraam Thank for the review. I am trying to improve my rust coding skills and contributing to open source is a good opportunity. |
|
@tertsdiepraam I am not to familiar with github, it still shows changed requested. Do i have to do something to request review. Furthermore, should i squash the commits or would you do that when you merge it? |
|
The "changes requested" will stay there until I approve, but it's not enforced so no need to worry about it. I've decided to not write/review any uutils code the next few weeks to stip myself from using it to procrastinate on an important project. The review will probably soon be continued by another maintainer when they have time. If you need me specifically you can still mention me. :) Also squashing would be nice! We could do it, but we might forget, so might be best if you do it. |
|
I squashed, would be nice if someone can get this merged. |
ea4b709 to
83189e0
Compare
|
|
||
| match parse_result { | ||
| Ok((_, weekday)) => Some(weekday), | ||
| Err(_) => None, |
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.
why don't you return a Result ?
here, it would be
Err(_) => Err("Failed to parse weekday"),
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 had this discussion with @tertsdiepraam, but I think the reason is this is used in parse_datetime and we only care about whether it was parsed or not.
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.
My reasoning was that we only care about the parsing the whole datetime. If a weekday fails, another type of item might still succeedsl.
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.
@sylvestre should i change it to Result?
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 @sylvestre its been a while, i am fine with whatever but it would be good to get this pr also merged, before we forget what it was about :) .
83189e0 to
8746c65
Compare
sylvestre
left a comment
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.
sorry, i didn't submitted my comments :(
src/parse_weekday.rs
Outdated
| let s = s.as_str(); | ||
|
|
||
| let parse_result: IResult<&str, Weekday> = nom::combinator::all_consuming(alt(( | ||
| value(Weekday::Mon, alt((tag("monday"), tag("mon")))), |
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.
what about using a macro like
// Helper macro to simplify tag matching
macro_rules! tag_match {
($day:expr, $($pattern:expr),+) => {
value($day, alt(($(tag($pattern)),+)))
};
}
to have
tag_match!(Weekday::Mon, "monday", "mon"),
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.
@sylvestre done
This commit resolves issue uutils#23. Adds parse_weekday function that uses chrono weekday parser with a map for edge cases. Adds tests cases to make sure it works correctly. Use nom for parsing.
8746c65 to
96db1a2
Compare
|
thanks |
@tertsdiepraam @cakebaker @sylvestre
This commit resolves issue #23.
Adds parse_weekday function that uses chrono weekday parser with a map for edge cases. Adds tests cases to make sure it works correctly.