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