adzap / timeliness

Fast date/time parsing for the control freak.
http://github.com/adzap/timeliness
MIT License
224 stars 28 forks source link

Error when parsing dates without day part #12

Closed eeng closed 5 years ago

eeng commented 11 years ago
irb(main):001:0> Timeliness.parse('Jan09', :date, format: 'mmmyy')
NoMethodError: undefined method `<' for nil:NilClass
    from /Users/Emma/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/timeliness-0.3.7/lib/timeliness/parser.rb:142:in `fast_date_valid_with_fallback'
    from /Users/Emma/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/timeliness-0.3.7/lib/timeliness/parser.rb:24:in `make_time'
    from /Users/Emma/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/timeliness-0.3.7/lib/timeliness/parser.rb:17:in `parse'
    from (irb):1
adzap commented 8 years ago

There defined behaviour to default values for a date at the moment. I guess there could be.

Are you assuming a 1 for day?

adzap commented 5 years ago

So the solution to this is remove the format

Timeliness.parse('Jan09', format: 'mmmyy')

The day that is used will be taken from the configured date default values in Timeliness.configuration.date_for_time_type where the default is lambda { Time.now }

The specifying the format prevents the default values being used in the current gem logic.