neilgupta / Sherlock

Natural-language event parser for Javascript
https://sherlock.neil.gg
MIT License
532 stars 32 forks source link

parse("Send those four emails before leaving work today by 1800") is wrong #25

Closed jminjie closed 6 years ago

jminjie commented 6 years ago

Calling parse() on the input text "Send those four emails before leaving work today by 1800" returns:

isAllDay: false eventTitle: send those four emails leaving work startDate: new Date(1900-01-01T08:00:00.000Z) endDate: new Date(2018-06-05T01:00:00.000Z)

Which seems to be setting the start date based on the words "before" and "1800"

I'm happy to help fix this if someone can point me in the right direction.

neilgupta commented 6 years ago

You're on the right track. Sherlock is searching for "before" and if it finds that anywhere in the string, it returns a date range from "jan 1, 1900" to whatever date you entered. I think the fix should just require editing the more_than_comparator and less_than_comparator regex (lines 36-37) to only match if those words appear at the end of the string. Should be pretty straightforward.