Conversation
fd9a5f7 to
93c6ced
Compare
93c6ced to
4c2227b
Compare
|
GNU testsuite comparison: |
| /// Convert a date string to iso if it is seperated by dots. | ||
| fn convert_to_iso(date_str: &str) -> Option<String> { | ||
| // Seperate the date from anything else, in case we have something like "01.01.2008 03:00 p.m." | ||
| let mut parts = date_str.splitn(2, ' '); |
There was a problem hiding this comment.
There is one exception where this approach will fail: GNU date allows spaces between month and year and so something like "01.01. 2008 03:00 p.m." is a valid date.
| let date_subparts: Vec<&str> = date_part.split('.').collect(); | ||
| if date_subparts.len() != 3 { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
With GNU date the year is optional. If it is missing, the current year is used. And so something like "01.01. 03:00 p.m." is a valid date.
There was a problem hiding this comment.
It might make sense to move the functionality over to https://github.com/uutils/parse_datetime . There we already use a parser library which could be helpful for the functionality I mentioned in the other comments.
There was a problem hiding this comment.
Yeah I was just looking for a such function there, anyways, should we add tests for dates like 01.01. 2008 03:00 p.m. and 01.01. 03:00 p.m.?
closes #14604