lzell / nickel

Nickel extracts date, time, and message information from naturally worded text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

having a dash "-" in the input with no date returns a daily occurrence beginning w/ the current day

codeodor opened this issue · comments

Example:

Nickel.parse "job search - apply at virgin intergalactic"

Returns:

message: "job search apply at virgin intergalactic", occurrences: [#<Occurrence type: daily, start_date: "20110428", interval: 1>] 

I would expect without any date information, it should return an empty array for occurrences.

Additionally, Nickel.parse "-" by itself results in NoMethodError: undefined method `interpret_date' for nil:NilClass

What's happening is that the query_formatting method is replacing "-" with "through", regardless of any other date information. Then the query_pre_processing method changes that to "today through" which is where it picks up the date.

So that means anything with "through" in it also gets turned into a date, even if it shouldn't. For example: "go through all tests and correct them" also gets an occurrence set for daily starting with the current date.

I wrote a couple of tests for this. I'm interested in fixing it, and my thought was to do something like this:

replace_hyphens if date_info_present? 
...
nsub!(/^(through|until)/,'today through') if date_info_present?

I haven't read through all the code yet, so before I go writing a new method to take care of it, is there anything like that already written that I could take advantage of (or parts that could be assembled together to create it)?