[PATCH] lib: add support for date:<expr>..! to mean date:<expr>..<expr>
authorJani Nikula <jani@nikula.org>
Sat, 15 Aug 2015 11:25:47 +0000 (14:25 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:21 +0000 (14:49 -0700)
2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a [new file with mode: 0644]

diff --git a/2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a b/2f/2b15294141dcb2852e7b94ebd5839b1ab3db3a
new file mode 100644 (file)
index 0000000..241af1c
--- /dev/null
@@ -0,0 +1,163 @@
+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 arlo.cworth.org (Postfix) with ESMTP id 2CA0B6DE17FD\r
+ for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:48 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.248\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.248 tagged_above=-999 required=5 tests=[AWL=0.472,\r
+  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id oiJMmBN0Od3U for <notmuch@notmuchmail.org>;\r
+ Sat, 15 Aug 2015 04:25:46 -0700 (PDT)\r
+Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
+ [209.85.212.169])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id F08716DE021E\r
+ for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:45 -0700 (PDT)\r
+Received: by wibhh20 with SMTP id hh20so42720009wib.0\r
+ for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:44 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
+ :references:mime-version:content-type:content-transfer-encoding;\r
+ bh=kO1xVViJfzx+unxR58RtuAtdQC/HNZotS0xPe8oCbrc=;\r
+ b=YMqq2iM1ijS2g3QZMSUJynAcoveZAJyHuLrmJaOLVo0/LMoArZ3IRPBddu+SzBZAK9\r
+ IsE9e2EEOQ3SRcPrf3q2y/XO7ACPplokwp/sY1PanZZugsOI5Itk0SkxTWGLh+joTw2T\r
+ f5F2KORwMtrJf36JXYMfV+klzM+Uy8XT4eGxpPAlXPDTE/l3yz/njxDko1PPLdSJiiN9\r
+ LRpMxDc03OacE3msADtXIo8w4XbvBt+Qpa2JrvMd8uXUVdm4CZgSy/pxv2h+Czc0S3+O\r
+ ctf03ZK4YsVVo6JesuCPp/rXTmJHfOBgd97cXGmqyibnitHioWj2Ww7kHU4Jd79GSrzf\r
+ n9AA==\r
+X-Gm-Message-State:\r
+ ALoCoQm08GaHFou1AT5fOvsMz+ymbYAE9wq2GN1xZyg85fSB8Gf2qKMfw7K7uS0/852e2DdIkbMG\r
+X-Received: by 10.194.117.5 with SMTP id ka5mr8984258wjb.50.1439637944265;\r
+ Sat, 15 Aug 2015 04:25:44 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
+ [188.238.79.131])\r
+ by smtp.gmail.com with ESMTPSA id gm20sm12517871wjc.17.2015.08.15.04.25.43\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 15 Aug 2015 04:25:43 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: David Bremner <david@tethera.net>, Jani Nikula <jani@nikula.org>,\r
+ notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: add support for date:<expr>..! to mean\r
+ date:<expr>..<expr>\r
+Date: Sat, 15 Aug 2015 14:25:47 +0300\r
+Message-Id: <1439637947-12147-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <87k2vegsda.fsf@maritornes.cs.unb.ca>\r
+References: <87k2vegsda.fsf@maritornes.cs.unb.ca>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Sat, 15 Aug 2015 11:25:48 -0000\r
+\r
+It doesn't seem likely we can support simple date:<expr> expanding to\r
+date:<expr>..<expr> any time soon. (This can be done with a future\r
+version of Xapian, or with a custom query query parser.) In the mean\r
+time, provide shorthand date:<expr>..! to mean the same. This is\r
+useful, as the expansion takes place before interpetation, and we can\r
+use, for example, date:yesterday..! to match from beginning of\r
+yesterday to end of yesterday.\r
+\r
+Idea from Mark Walters <markwalters1009@gmail.com>.\r
+---\r
+ doc/man7/notmuch-search-terms.rst | 12 +++++++-----\r
+ lib/parse-time-vrp.cc             |  5 +++++\r
+ test/T500-search-date.sh          |  4 ++++\r
+ 3 files changed, 16 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
+index 1d27ac1e6de5..3b35a32b7d23 100644\r
+--- a/doc/man7/notmuch-search-terms.rst\r
++++ b/doc/man7/notmuch-search-terms.rst\r
+@@ -270,6 +270,13 @@ In this case, <since> is taken as the earliest time it could describe\r
+ could describe (the end of yesterday). Similarly, date:january..february\r
+ matches from the beginning of January to the end of February.\r
\r
++date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The\r
++expansion takes place before interpretation, and thus, for example,\r
++date:monday..! matches from the beginning of Monday until the end of\r
++Monday. (Note that entering date:<expr> without "..", for example\r
++date:yesterday, won't work, as it's not interpreted as a range\r
++expression at all. Again, use date:yesterday..!)\r
++\r
+ Currently, we do not support spaces in range expressions. You can\r
+ replace the spaces with '\_', or (in most cases) '-', or (in some cases)\r
+ leave the spaces out altogether. Examples in this man page use spaces\r
+@@ -280,11 +287,6 @@ to specify date:..<until> or date:<since>.. to not limit the start or\r
+ end time, respectively. Pre-1.2.1 Xapian does not report an error on\r
+ open ended ranges, but it does not work as expected either.\r
\r
+-Entering date:expr without ".." (for example date:yesterday) won't work,\r
+-as it's not interpreted as a range expression at all. You can achieve\r
+-the expected result by duplicating the expr both sides of ".." (for\r
+-example date:yesterday..yesterday).\r
+-\r
+ Relative date and time\r
+ ----------------------\r
\r
+diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
+index 33f07db3410e..03804cf50fa8 100644\r
+--- a/lib/parse-time-vrp.cc\r
++++ b/lib/parse-time-vrp.cc\r
+@@ -31,6 +31,7 @@ Xapian::valueno\r
+ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
+ {\r
+     time_t t, now;\r
++    std::string b;\r
\r
+     /* Require date: prefix in start of the range... */\r
+     if (STRNCMP_LITERAL (begin.c_str (), PREFIX))\r
+@@ -38,6 +39,7 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
\r
+     /* ...and remove it. */\r
+     begin.erase (0, sizeof (PREFIX) - 1);\r
++    b = begin;\r
\r
+     /* Use the same 'now' for begin and end. */\r
+     if (time (&now) == (time_t) -1)\r
+@@ -51,6 +53,9 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
+     }\r
\r
+     if (!end.empty ()) {\r
++      if (end == "!" && ! b.empty ())\r
++          end = b;\r
++\r
+       if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
+           return Xapian::BAD_VALUENO;\r
\r
+diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh\r
+index b28496b78e2e..f5cea421d785 100755\r
+--- a/test/T500-search-date.sh\r
++++ b/test/T500-search-date.sh\r
+@@ -8,6 +8,10 @@ test_begin_subtest "Absolute date range"\r
+ output=$(notmuch search date:2010-12-16..12/16/2010 | notmuch_search_sanitize)\r
+ test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
\r
++test_begin_subtest "Absolute date range with 'same' operator"\r
++output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)\r
++test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
++\r
+ test_begin_subtest "Absolute time range with TZ"\r
+ notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT\r
+ cat <<EOF >EXPECTED\r
+-- \r
+2.1.4\r
+\r