chronic icon indicating copy to clipboard operation
chronic copied to clipboard

Parse datetime in a full string

Open arjunmenon opened this issue 7 years ago • 1 comments

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.

arjunmenon avatar Jun 26 '18 18:06 arjunmenon

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.

davispuh avatar Jun 27 '18 17:06 davispuh