mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.24k stars 465 forks source link

Parse datetime in a full string #377

Open arjunmenon opened 6 years ago

arjunmenon commented 6 years ago

Hey I am trying to parse datetime from a string.

"17 hours ago ... The Twitter account, which rates images of dogs, changed one canine's name from Kanan to George, drawing criticism. "

Now this string has "17 hours ago" which on its own gets parsed but not with the full string, which return a nil.

Alternatively, if I do a to_time, from the Rails Datetime class, on it - it gets parsed to 2018-06-27 17:00:00 +0530, a datetime object but is not at all accurate. (I ran this at dot midnight, it simply returned 1700 to the current date)

Even though Datetime tried to find strings which can represent dates or times, but the Datetime class is too too forgiving. It becomes inaccurate.

So how can we make chronic find patterns of string which it knows represent datetime, from full strings? This should be possible.

davispuh commented 6 years ago

It's not really supported, it kinda works for some texts/cases but if text contains any keyword it most likely will be parsed wrongly.

If you remove from and one from this text then it will work.