NoMethodError: undefined method `offset' for #<Chronic::RepeaterTime:0x101d00d48> #86

Closed
ottumm opened this Issue Feb 20, 2012 · 5 comments

Comments

Projects
None yet
2 participants

ottumm commented Feb 20, 2012

Executing

Chronic.parse("Serving you in Brisbane, 8000 Marina Blvd, 11:30", {:now => Time.parse("Wed Feb 15 09:32:18 -0800 2012"), :ambiguous_time_range => 10})

yields

NoMethodError: undefined method `offset' for #<Chronic::RepeaterTime:0x101d00d48>
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/handlers.rb:321:in `handle_srp'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/handlers.rb:329:in `handle_s_r_p'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/handlers.rb:335:in `handle_p_s_r'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/handler.rb:70:in `send'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/handler.rb:70:in `invoke'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/chronic.rb:309:in `tokens_to_span'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/chronic.rb:306:in `each'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/chronic.rb:306:in `tokens_to_span'
    from /Library/Ruby/Gems/1.8/gems/chronic-0.6.7/lib/chronic/chronic.rb:83:in `parse'

ottumm commented Feb 20, 2012

I tried to find a smaller reproducible case, but removing almost anything gets rid of the error.

Collaborator

leejarvis commented May 31, 2012

There's not really much way to get around this. Chronic isn't built for extracting times, but rather parsing them. That is, Chronic expects something which represents a string that should return a new Time object. Your time should first be extracted from your string before it's sent to Chronic.

leejarvis closed this May 31, 2012

@leejarvis leejarvis pushed a commit that referenced this issue May 31, 2012

Lee Jarvis only execute #offset on repeaters which handle them
ref #86
7585ccb

ottumm commented Jun 1, 2012

Yeah, that makes sense. I'm trying to use Chronic to both extract and parse by splitting a sentence up into its component phrases and attempting to parse each phrase (in order of decreasing length) with Chronic. If Chronic returns nil, the algorithm moves onto the next phrase.

So, for this issue, I don't expect Chronic to be able to extract the time from the long phrase, but I would like it to return nil instead of throwing an exception. Does that seem reasonable? If so, I can attempt a fix.

On Thursday, May 31, 2012 at 9:51 AM, Lee Jarvis wrote:

There's not really much way to get around this. Chronic isn't built for extracting times, but rather parsing them. That is, Chronic expects something which represents a string that should return a new Time object. Your time should first be extracted from your string before it's sent to Chronic.


Reply to this email directly or view it on GitHub:
#86 (comment)

Collaborator

leejarvis commented Jun 1, 2012

Yeah, Chronic should of course not raise an error like that but should
return nil. See the commit I referenced above, with that in place
chronic will return nil for the string you've provided. It'll be
released soon.

On 1 Jun 2012, at 04:33, Mike Ottum
reply@reply.github.com
wrote:

Yeah, that makes sense. I'm trying to use Chronic to both extract and parse by splitting a sentence up into its component phrases and attempting to parse each phrase (in order of decreasing length) with Chronic. If Chronic returns nil, the algorithm moves onto the next phrase.

So, for this issue, I don't expect Chronic to be able to extract the time from the long phrase, but I would like it to return nil instead of throwing an exception. Does that seem reasonable? If so, I can attempt a fix.

On Thursday, May 31, 2012 at 9:51 AM, Lee Jarvis wrote:

There's not really much way to get around this. Chronic isn't built for extracting times, but rather parsing them. That is, Chronic expects something which represents a string that should return a new Time object. Your time should first be extracted from your string before it's sent to Chronic.


Reply to this email directly or view it on GitHub:
#86 (comment)


Reply to this email directly or view it on GitHub:
#86 (comment)

ottumm commented Jun 2, 2012

Oh, awesome! I missed the commit above, thanks for fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment