iainbeeston / nickel

Nickel extracts date, time, and message information from naturally worded text.
MIT License
113 stars 17 forks source link

Year not extracted #24

Open aeturneus opened 10 years ago

aeturneus commented 10 years ago

Recently updated the codebase for my app which uses nickel and I am running into an issue where the year is not identified as an occurence, and the current year (2014) or the upcoming year (2015) is used instead by default, depending on the date:

example:

n = Nickel.parse("October 28, 1969.") n.inspect

results in the following output:

date: message: "1969", occurrences: [#Occurrence type: single, start_date: "20141028"]

aeturneus commented 9 years ago

A little help? I still haven't been able to get Nickel to parse years - it detects the day of the month and returns the year as a message. Not sure what might be causing this issue or how to fix it.

iainbeeston commented 9 years ago

Sorry, it's rather difficult to fix individual issues in nickel at the moment. I have a refactor in the works, which will help (and also allow users to supplement nickel with their own overrides), but it's not ready yet.

If your example is a real one, and you're just parsing dates with no messages, you might want to try chronic instead? ( https://github.com/mojombo/chronic)

aeturneus commented 9 years ago

Came up with a (very) quick and dirty workaround for the time being that works for my use case but has some obvious problems.

        n = Nickel.parse(date)
        if n.occurrences.empty? == false
          year = /(\d{4})+/.match(n.message).to_a.shift
          if n.message != nil && n.message != "" 
            message = n.message.gsub(year, '')
          end
          n.occurrences.each { |d|
            date = DateTime.strptime(d.start_date.date,"%Y%m%d")
            date = date.change(:year => year.to_i)
           }
        end