Conversation
|
GNU testsuite comparison: |
src/uu/touch/src/touch.rs
Outdated
| return match date_from_modifier(modifier, parsed) { | ||
| Ok(new_date) => Ok(datetime_to_filetime(&new_date.and_utc())), | ||
| Err(e) => Err(e), | ||
| }; |
There was a problem hiding this comment.
I think it could be simplified with:
| return match date_from_modifier(modifier, parsed) { | |
| Ok(new_date) => Ok(datetime_to_filetime(&new_date.and_utc())), | |
| Err(e) => Err(e), | |
| }; | |
| return date_from_modifier(modifier, parsed).map(|new_date| datetime_to_filetime(&new_date.and_utc())); |
| if let Ok((parsed, modifier)) = NaiveDateTime::parse_and_remainder(s, fmt) { | ||
| if modifier.is_empty() { | ||
| return Ok(datetime_to_filetime(&parsed.and_utc())); | ||
| } | ||
| return match date_from_modifier(modifier, parsed) { | ||
| Ok(new_date) => Ok(datetime_to_filetime(&new_date.and_utc())), | ||
| Err(e) => Err(e), | ||
| }; |
There was a problem hiding this comment.
can probably be simplified too by something like
| if let Ok((parsed, modifier)) = NaiveDateTime::parse_and_remainder(s, fmt) { | |
| if modifier.is_empty() { | |
| return Ok(datetime_to_filetime(&parsed.and_utc())); | |
| } | |
| return match date_from_modifier(modifier, parsed) { | |
| Ok(new_date) => Ok(datetime_to_filetime(&new_date.and_utc())), | |
| Err(e) => Err(e), | |
| }; | |
| if let Ok((parsed, modifier)) = NaiveDateTime::parse_and_remainder(s, fmt) { | |
| return if modifier.is_empty() { | |
| Ok(datetime_to_filetime(&parsed.and_utc())) | |
| } else { | |
| date_from_modifier(modifier, parsed).map(|new_date| datetime_to_filetime(&new_date.and_utc())) | |
| }; | |
| } | |
src/uu/touch/src/touch.rs
Outdated
| if modifier.is_empty() { | ||
| return Ok(datetime_to_filetime(&parsed)); | ||
| } | ||
| return match date_from_modifier(modifier, parsed) { |
There was a problem hiding this comment.
same, Err(e) => Err(e),
can often be simplified
|
Lot of work probably went into this, bravo |
| )); | ||
| } | ||
| date = if time >= 0 { | ||
| date.add(Months::new((12 * time) as u32)) |
There was a problem hiding this comment.
codecov suggests that this line isn't covered, could you please fix it? thanks
| if i >= bytes.len() { | ||
| break; | ||
| } | ||
| if let n @ 48..=57 = bytes[i] { |
There was a problem hiding this comment.
please replace 48 & 57 by variable names
| } | ||
|
|
||
| fn parse_num(&mut self) -> Result<i64, ParseError> { | ||
| while self.cursor < self.haystack.len() && self.haystack[self.cursor].is_ascii_whitespace() |
There was a problem hiding this comment.
please create a function:
fn skip_whitespace(&mut self) {
while self.cursor < self.haystack.len() && self.haystack[self.cursor].is_ascii_whitespace() {
self.cursor += 1;
}
}
| } | ||
|
|
||
| fn parse_unit(&mut self) -> Result<ChronoUnit, ParseError> { | ||
| while self.cursor < self.haystack.len() && self.haystack[self.cursor].is_ascii_whitespace() |
There was a problem hiding this comment.
and replace this one too
| } | ||
| let bytes = &self.haystack[self.cursor..].to_ascii_lowercase(); | ||
| match bytes[0] { | ||
| b'd' => { |
There was a problem hiding this comment.
i can probably by simplified by something like:
let units = [
(b'd', "day", ChronoUnit::Day),
(b'w', "week", ChronoUnit::Week),
(b'm', "month", ChronoUnit::Month),
(b'y', "year", ChronoUnit::Year),
(b'h', "hour", ChronoUnit::Hour),
(b's', "second", ChronoUnit::Second),
];
for &(byte, unit_str, chrono_unit) in &units {
if bytes.starts_with(unit_str) {
self.cursor += unit_str.len();
return Ok(chrono_unit);
}
}
There was a problem hiding this comment.
Thank you for reviewing this PR. I can implement the changes later this evening.
tertsdiepraam
left a comment
There was a problem hiding this comment.
@sylvestre, you seem to have a pretty good grasp on this already. Shouldn't this be fixed in parse_datetime?
I actually did consider this, but I figured it is not technically parsing a date but a modifier to a date. I can move the changes over to |
|
Yes, that's what parse datetime is for. It's supposed to parse the format described here: https://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html, which includes this part I believe. Porting it would be great! |
|
I made the suggested changes including adding integration testing. I also increased testing to satisfy the code coverage bot, however I'm not sure I was able to get everything. I apologize in advance if the I did something incorrectly; I don't know git very well. |
|
what do you think about moving it into https://github.com/uutils/parse_datetime/ ? |
Oh, I see. I misunderstood @tertsdiepraam. Yes, I'm willing to move my work to One observation is that In short, I just need to a day or two to reorient myself. But I am confident I can figure it out since I already gained a decent understanding while working on this PR. |
|
@sylvestre @tertsdiepraam I ran into some interesting issues while working to transfer this PR to |
|
@dcechano sorry but do you have an update ? thanks |
Yes sir. I am very sorry for the long delay but working out a solution that covers edge cases turned out to be quite challenging. I have been working in the parse_datetime repo as suggested and getting a PR ready. What has been taking so long is that I had to implement the core logic (which was challenging in its own right) then integrate it into the larger library via After the PR, which I have set a hard goal of getting in by the end of this week, |
|
@sylvestre & @tertsdiepraam I have a PR in that is a major step in addressing #3505. I'm looking forward to hearing what you guys think. Thank you! |
|
sorry, we dropped the ball here :( |
|
@dcechano ping ? :) |
|
The issue seems to be fixed anyway |
|
Yes, I think this is fixed now, so I'll close this. Future improvements should go in https://github.com/uutils/parse_datetime |
This commit addresses #3505. I added a
parse_date_modification.rsmodule touucore::parserand used it intouch.rs. I added tests totouch.rsto prove the parser works and is not buggy. In theory these changes can also help with similar issues indate.rsbut I wanted to keep the PR to one issue at a time.Thank you for considering my pull request and I welcome feedback if you guys have any.