[sup-talk] [PATCH] Natural language date searches

Marcus Williams marcus-sup at bar-coded.net
Fri Nov 9 15:29:58 EST 2007


On 9.11.2007, William Morgan wrote:
> Modified to skip parsing if Chronic isn't available, and applied.
> Thanks!
> 
> Also made it accept one-word Chronic tokens without parentheses,
> although "after:yesterday" means "after yesterday noon", which maybe is
> not so useful...

I think I may have worked out how to fix that - change the parse
method to be:

realdate = Chronic.parse(datestr, :guess => false).begin

If guess is set to false it looks like Chronic always returns a span
and you can just select the beginning of the span.  At the moment I'm
pretty sure you always want the beginning of the span in search
situations. Certainly makes the single tokens more usable:

irb(main):003:0> Chronic.parse("november", :guess => false).begin
=> Thu Nov 01 00:00:00 +0000 2007
irb(main):004:0> Chronic.parse("monday", :guess => false).begin
=> Mon Nov 12 00:00:00 +0000 2007
irb(main):005:0> Chronic.parse("24 hours ago", :guess => false).begin
=> Thu Nov 08 20:24:14 +0000 2007
irb(main):006:0> Chronic.parse("sunday", :guess => false).begin
=> Sun Nov 11 00:00:00 +0000 2007
irb(main):008:0> Chronic.parse("last sunday", :guess => false).begin
=> Sun Nov 04 00:00:00 +0000 2007
irb(main):010:0> Chronic.parse("first monday of november", :guess => false).begin
=> Mon Nov 05 00:00:00 +0000 2007

Marcus


More information about the sup-talk mailing list