[PATCH 3/4] Use the time/date parser for after: and before: prefixes
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 23 Jan 2011 11:47:26 +0000 (12:47 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:44 +0000 (09:37 -0800)
b0/df08a6ccc4bae6a3e15123bd8ff46b42417b2d [new file with mode: 0644]

diff --git a/b0/df08a6ccc4bae6a3e15123bd8ff46b42417b2d b/b0/df08a6ccc4bae6a3e15123bd8ff46b42417b2d
new file mode 100644 (file)
index 0000000..c5dfc4d
--- /dev/null
@@ -0,0 +1,104 @@
+Return-Path: <sojkam1@fel.cvut.cz>\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 69CFA42D280\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Jan 2011 03:47:41 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 jxZCRljl50yP for <notmuch@notmuchmail.org>;\r
+       Sun, 23 Jan 2011 03:47:40 -0800 (PST)\r
+Received: from mail.loccal.net (gw.loccal.net [94.142.235.206])\r
+       by olra.theworths.org (Postfix) with ESMTP id 635D4431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Jan 2011 03:47:40 -0800 (PST)\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by mail.loccal.net (Postfix) with ESMTP id 7AC481BDB2;\r
+       Sun, 23 Jan 2011 13:00:55 +0100 (CET)\r
+X-Virus-Scanned: amavisd-new at loccal.net\r
+Received: from mail.loccal.net ([127.0.0.1])\r
+       by localhost (mail.loccal.net [127.0.0.1]) (amavisd-new, port 10024)\r
+       with LMTP id pUJ0f8wsru5H; Sun, 23 Jan 2011 13:00:51 +0100 (CET)\r
+Received: from steelpick.2x.cz (unknown [10.21.129.4])\r
+       by mail.loccal.net (Postfix) with ESMTPS id 824031BDAE;\r
+       Sun, 23 Jan 2011 13:00:51 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.72)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1PgyPu-0005i5-Lh; Sun, 23 Jan 2011 12:47:34 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] Use the time/date parser for after: and before: prefixes\r
+Date: Sun, 23 Jan 2011 12:47:26 +0100\r
+Message-Id: <1295783247-21900-4-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1295783247-21900-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1295783247-21900-1-git-send-email-sojkam1@fel.cvut.cz>\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, 23 Jan 2011 11:47:41 -0000\r
+\r
+This allows to have queries like:\r
+  after:10am\r
+  after:"10:00 GMT"\r
+  after:"now -2 hours"\r
+  after:"2 hours ago"\r
+  after:yesterday\r
+  after:"last month"\r
+---\r
+ lib/database.cc |   14 ++++++++------\r
+ 1 files changed, 8 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index cb02220..615b408 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -19,6 +19,7 @@\r
+  */\r
\r
+ #include "database-private.h"\r
++#include "getdate.h"\r
\r
+ #include <iostream>\r
\r
+@@ -643,16 +644,17 @@ transform_date (_notmuch_token_t *root, void *opaque)\r
+       int before = (strcmp (root->text, "before") == 0);\r
+       if (after || before) {\r
+           _notmuch_token_t *tok = root->left;\r
+-          struct tm t;\r
++          bool ok;\r
++          struct timespec result, now;\r
+           time_t time_value;\r
+-          char *end, *serialzed;\r
++          char *serialzed;\r
\r
+           /* Parse the date */\r
+           assert (tok && tok->type == TOK_LIT);\r
+-          memset(&t, 0, sizeof(t));\r
+-          end = strptime (tok->text, "%Y/%m/%d", &t);\r
+-          time_value = mktime(&t);\r
+-          if (!end || *end || time_value == -1) {\r
++          clock_gettime (CLOCK_REALTIME, &now);\r
++          ok = get_date (&result, tok->text, &now);\r
++          time_value = result.tv_sec;\r
++          if (!ok || time_value == -1) {\r
+               char *msg = talloc_asprintf (root, "Invalid date \"%s\"",\r
+                                            tok->text);\r
+               return _notmuch_token_create_term (root, TOK_ERROR, msg);\r
+-- \r
+1.7.2.3\r
+\r