Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Year not extracted #24

Open
aeturneus opened this issue Jul 21, 2014 · 3 comments
Open

Year not extracted #24

aeturneus opened this issue Jul 21, 2014 · 3 comments

Comments

@aeturneus
Copy link

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants