Re: [RFC PATCH 0/2] natural language date range search
authorJani Nikula <jani@nikula.org>
Sat, 25 Feb 2012 19:53:27 +0000 (21:53 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:59 +0000 (09:44 -0800)
91/66a0fe13ae168cd2987c30de434eb4140dc9b6 [new file with mode: 0644]

diff --git a/91/66a0fe13ae168cd2987c30de434eb4140dc9b6 b/91/66a0fe13ae168cd2987c30de434eb4140dc9b6
new file mode 100644 (file)
index 0000000..8187b89
--- /dev/null
@@ -0,0 +1,306 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A6E0D431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:05:23 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Unj1Q7302c8t for <notmuch@notmuchmail.org>;\r
+       Sat, 25 Feb 2012 21:05:22 -0800 (PST)\r
+Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
+       [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 269FD431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:05:21 -0800 (PST)\r
+Received: by lahd3 with SMTP id d3so4359286lah.26\r
+       for <notmuch@notmuchmail.org>; Sat, 25 Feb 2012 21:05:19 -0800 (PST)\r
+Received-SPF: pass (google.com: domain of jani@nikula.org designates\r
+       10.152.123.68 as permitted sender) client-ip=10.152.123.68; \r
+Authentication-Results: mr.google.com;\r
+       spf=pass (google.com: domain of jani@nikula.org\r
+       designates 10.152.123.68 as permitted sender)\r
+       smtp.mail=jani@nikula.org\r
+Received: from mr.google.com ([10.152.123.68])\r
+       by 10.152.123.68 with SMTP id ly4mr6923784lab.13.1330232719286\r
+       (num_hops = 1); Sat, 25 Feb 2012 21:05:19 -0800 (PST)\r
+Received: by 10.152.123.68 with SMTP id ly4mr5018536lab.13.1330199611811;\r
+       Sat, 25 Feb 2012 11:53:31 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
+       [84.248.80.253])\r
+       by mx.google.com with ESMTPS id w10sm10806424lbe.14.2012.02.25.11.53.29\r
+       (version=SSLv3 cipher=OTHER); Sat, 25 Feb 2012 11:53:30 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, notmuch@notmuchmail.org\r
+Subject: Re: [RFC PATCH 0/2] natural language date range search\r
+In-Reply-To: <m2mx87j6lz.fsf@guru.guru-group.fi>\r
+References: <cover.1329689945.git.jani@nikula.org>\r
+       <m2mx87j6lz.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.11.1+206~gc02a53f (http://notmuchmail.org) Emacs/23.3.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sat, 25 Feb 2012 21:53:27 +0200\r
+Message-ID: <87ehtiitag.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQk/WIQZLZVu84eW/JEysuCmUfDexFcrGEH+x28jHu4CXUsL1wxC3gQ0dXh2VMvGaWqdzn2U\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 26 Feb 2012 05:05:23 -0000\r
+\r
+On Sat, 25 Feb 2012 17:05:44 +0200, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> On Mon, 20 Feb 2012 00:55:50 +0200, Jani Nikula <jani@nikula.org> wrote:\r
+> > Hi all, these patches add support for natural language date range search\r
+> > of the form date:since..until, where since and until can be fairly free\r
+> > form date/time expressions in English.\r
+> > \r
+> > Examples:\r
+> > \r
+> > date:two-days..yesterday (all mail in the two days before today)\r
+> > date:12h.. (all mail since 12 hrs ago)\r
+> > date:november..november (all mail in previous november)\r
+> > date:2011.. (all mail since the beginning of 2011)\r
+> > date:last-week..this-week (all mail over last and current week)\r
+> > date:5/10/2011-12:34:55..10pm_2012-01-14\r
+> > \r
+> > Plus plenty more and combinations of the above.\r
+> \r
+> Pretty c00l, the above and the code.\r
+\r
+Thanks! :)\r
+\r
+> > \r
+> > The repository for the date/time parser with a command line tool is at\r
+> > [1], and there's a README [2] with a bunch of details too.\r
+> \r
+> By seeing the thoughts thrown in IRC there seems to be plenty if things\r
+> to resolve until something like this is going to be available in stock\r
+> notmuch. In the meanwhile I provide some ideas into the soup; maybe\r
+> our collective mind can have some use of this.\r
+> \r
+> \r
+> Q: Could 'date:timestr' be converted to 'date:timestr..timestr' ?\r
+\r
+AFAICT this would require the custom query parser.\r
+\r
+> In this idea -<timestr> means relative time and <timestr> absolute\r
+> time. The the time string consists of number and letter and assume\r
+> the above suggestion for date:timestr (<- == date:timestr..timestr)\r
+> Letters are s seconds  h hours  d days  w weeks  m months (more\r
+> useful than for minutes) and  y years.\r
+\r
+I'll put it bluntly: show me the code! ;)\r
+\r
+I'll comment below how your examples can be expressed with working code\r
+in this series, just for comparison, and to show what can be done with\r
+this.\r
+\r
+> date:-2000s     email exactly 2000 seconds ago (not very useful)\r
+\r
+date:2000s..2000s\r
+\r
+> date:-2000s..   since 2000 secs in past\r
+\r
+date:2000s..\r
+date:1000s500s500s.. (all accumulated)\r
+\r
+> date:..-2000s   up to 2000 secs in past\r
+\r
+date:..2000s\r
+\r
+> date:3600s      email with date 01:00 -- today if (local) time is\r
+>                 more than 1am. yesterday if less. If there is not\r
+>                 mail with date exactly that then no email matches\r
+>                 (i.e. same usefullness applies as above)\r
+> date:3600s..    email with date since 01:00 (same today/yesterday\r
+>                 resolvation like above)\r
+\r
+Okay, there's no easy way to express it like this.\r
+\r
+> date:12h..      since noon, either yesterday (time less than 12pm)\r
+>                 or today (currently afternoon)\r
+\r
+date:noon.. \r
+date:12pm..\r
+date:12:00..\r
+date:12:00:00..\r
+\r
+(I think in my implementation currently refers to today regardless of\r
+current time; there's a REVISIT comment about that. Not difficult to\r
+fix.)\r
+\r
+> date:12h        like above, but since 12:00 to 13:00\r
+> date:12h..12h   ditto\r
+\r
+For example date:noon..13:00\r
+\r
+> date:6pm..      since 18:00 either today (current time > 6pm) or yesterday\r
+\r
+The same.\r
+\r
+> date:-12h..     since 12 hours ago\r
+\r
+date:12h..\r
+\r
+> date:-12h       since 12 hours ago to 11 hours ago\r
+\r
+date:12h..11hrs\r
+\r
+> date:-1h        last hour\r
+\r
+date:1h..\r
+\r
+> date:0h         today 12am - 01am \r
+\r
+For example date:00:00..01am\r
+\r
+> date:-0d        today\r
+\r
+To cover the whole day, date:today..today\r
+\r
+> date:-0d..      ditto\r
+\r
+date:0d..0d (from zero days ago to zero days ago, rounded accordingly)\r
+\r
+In fact, in my implementation "today" is simply the same as 0 days ago.\r
+\r
+> date:-1d        yesterday\r
+\r
+date:yesterday..yesterday\r
+\r
+> date:-1d..      yesterday & today\r
+\r
+date:1d..\r
+\r
+> date:-2d        2 days ago\r
+\r
+For example date:two-days..2d\r
+\r
+> date:-2d..      day before yesterday, yesterday & today\r
+\r
+date:2d..\r
+\r
+> date:0d         last sunday (if today sunday, today (so being consistent))\r
+\r
+date:sunday..sunday (if today sunday, one week ago)\r
+\r
+> date:1d         last monday (like above)\r
+> date:6d         last saturday (like above)\r
+> date:7d         last sunday (same as 0d)\r
+\r
+Just weekday names.\r
+\r
+> date:-0w        current week (does week start sun or mon)\r
+\r
+For example date:0w...this-week\r
+\r
+> date:-1w        last week (same as above)\r
+\r
+For example date:last-week..1w\r
+\r
+> date:-2w..      since beginning of 2 weeks ago\r
+\r
+date:2w..\r
+\r
+> date:1w         (ISO) week number ? current week it this is same week  \r
+>                 number. this week last year if current week is less.\r
+> date:1w..    since the above date resolved.\r
+\r
+N/A, my parser does not support week numbers.\r
+\r
+> date:11m     last november (m is more useable in month than in minute)\r
+\r
+date:november..november, or by specifying the year date:2011-11..2011-11\r
+\r
+> date:11m..      since last november\r
+\r
+date:november..\r
+\r
+> date:-11m       whole month 11 months ago\r
+\r
+date:11mon..11M (lower case m is minutes)\r
+\r
+> date:-11m..  since beginning of 11 months ago\r
+\r
+date:11months..\r
+\r
+> date:70y     year 1970\r
+\r
+date:1970..1970\r
+\r
+> date:69y        year 2069\r
+\r
+date:2069..2069\r
+\r
+> date:0y         year 2000\r
+\r
+date:2000..2000\r
+\r
+> date:99y..      since beginning of 1999\r
+\r
+date:2000..\r
+\r
+(It's possible to use 2-digit years in combination with some more\r
+context, e.g. 1.1.99)\r
+\r
+> date:-0y        this year\r
+\r
+date:this-year..this-year\r
+\r
+> date:-1y        last year\r
+\r
+date:last-year..1y\r
+\r
+> This is incomplete, but pretty easy to use format. Letters from English\r
+> language. What is missing letter for month (M?) ar mday (D?). All thought\r
+> as in local time...\r
+> \r
+> ... strings could be concatenated: for example: -3d11h (meaning second\r
+> always absolute). Need to be in granularity order (or something). Timezone\r
+> could be added (pst, utc, eest, z -- and even like -11 or +4\r
+> ( -2y11m+7 meaning year 2010 november in timezone utc + 7 (this year: 2012))\r
+\r
+My implementation allows adding any number of relative dates, and they\r
+are accumulated, but only towards past. Relative date can be combined\r
+with absolute date, as long as the same absolute unit is not specified\r
+twice (can't say "january february", but "january one month" is one\r
+month back from january).\r
+\r
+(With a couple of small further patches still in my local tree) you can\r
+specify time zone for all of the above.\r
+\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+\r
+> \r
+> Of course range date:-2d..-5h would be supported.\r
+> \r
+> > BR,\r
+> > Jani.\r
+> > \r
+> > \r
+> > [1] https://gitorious.org/parse-time-string/parse-time-string\r
+> > [2] https://gitorious.org/parse-time-string/parse-time-string/blobs/master/README\r
+> > \r
+> \r
+> Tomi\r
+> \r