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

Getting nil trying to parse 'March 10, 2013 at 12am' #177

Open
Jacobkg opened this issue Mar 3, 2013 · 3 comments
Open

Getting nil trying to parse 'March 10, 2013 at 12am' #177

Jacobkg opened this issue Mar 3, 2013 · 3 comments
Labels

Comments

@Jacobkg
Copy link

Jacobkg commented Mar 3, 2013

Chronic.time_class.zone
=> (GMT-05:00) Eastern Time (US & Canada)
Chronic.parse "March 10, 2013 at 12am"
=> nil

@TALlama
Copy link

TALlama commented Mar 5, 2013

The problem seems to be here. Coming into that call to next, we have the following state:

    @current_time: nil
    pointer: :future
    first: true
    midnight: 2013-03-10 00:00:00 -0800 (a Time)
    yesterday_midnight: 2013-03-09 00:00:00 -0800 (a Time)
    tomorrow_midnight: 2013-03-11 00:00:00 -0700 (a Time)
    offset_fix: -3600
    @time: 2013-03-10 00:00:00 -0800
    @type.class: Chronic::RepeaterTime::Tick
    @type.time: 0
    @type.ambiguous?: true

We then hit line 80 and cycle through:

  • midnight + @type.time + offset_fix resolves to 2013-03-09 23:00:00 -0800 (a Time), which isn't after @now and is rejected
  • midnight + half_day + @type.time + offset_fix is after @now, and is accepted

So we pop the stack and end up at Chronic::Handlers#find_within, where our returned span is (2013-03-10 12:00:00 -0700..2013-03-10 12:00:01 -0700) (one second long), and doesn't cover midnight, so we fall off the end of the method and return nil, which also seems problematic.

I can't see a simple solution to this problem, but it can be easily replicated by doing a simple Chronic.parse('Mar 10, 2013 12:00am'). Note that Chronic.parse("Mar 10, 2013 midnight") works fine, however, since it hits a different repeater_method.

@TALlama
Copy link

TALlama commented Mar 5, 2013

I found that the easiest way to trace the problem was by monkey-patching the code and inserting putses when I needed them; the above drop is a snippet of the output. The full monkey-patch, which can be run on a fresh console to show the step-by-step, is on Gist.

@bostonaholic
Copy link

+1

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

No branches or pull requests

3 participants