stevedonovan / chrono-english

Converting informal English dates (like `date` command) to chrono DateTime in Rust
MIT License
57 stars 14 forks source link

Unexpected result for today's weekday with time #6

Open tokudan opened 5 years ago

tokudan commented 5 years ago

The result of the parsing of a weekday with a time seems unexpected for me:

$ cargo run --quiet --example parse-date -- 'friday 18:00'
token None
base Fri Oct 19 15:13:01 2018 +0200 (2018-10-19T15:13:01.555812324+02:00)
calc Fri Oct 26 18:00:00 2018 +0200 (2018-10-26T18:00:00+02:00)

Considering that "now" is Friday before 18:00, I would have expect that "friday 18:00" resolves to "today 18:00". Instead the parsing seems to be "friday" -> next friday 00:00 "18:00" -> set time on that day to "18:00"

That would make parsing schedules easier and matches what the date command produces:

$ date --date="friday 18:00"
Fr 19. Okt 18:00:00 CEST 2018
stevedonovan commented 5 years ago

I think you are quite right - there are two fixes in this commit. The first simply makes sure that if the desired day of week and the base day of week are the same, we don't try to do the jump ahead. The second then checks the relative time between 'now' and desired time and does the jump if now is past the desired time.

The first feels correct, I'm not entirely sure about the second.