From mboxrd@z Thu Jan 1 00:00:00 1970 From: marcus-sup@bar-coded.net (Marcus Williams) Date: Fri, 09 Nov 2007 20:29:58 +0000 Subject: [sup-talk] [PATCH] Natural language date searches In-Reply-To: <1194633682-sup-962@south> References: <1193436327-sup-5753@tomsk> <1193519205-sup-6445@tomsk> <1194633682-sup-962@south> Message-ID: <1194639409-sup-6180@tomsk> 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