Support weekdays in parse_datetime#34
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.
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
|
|
||
| // 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.
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.
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.
Does using From<DateTime<FixedOffset>> for DateTime<Local> work here or is the naive_local necessary?
| #[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.
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.
I am not sure how to best not use local but agreed.
There was a problem hiding this comment.
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.
why don't you return a Result ?
here, it would be
Err(_) => Err("Failed to parse weekday"),
There was a problem hiding this comment.
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.
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.
@sylvestre should i change it to Result?
There was a problem hiding this comment.
@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.
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.
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"),
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.