--- /dev/null
+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 6DF91431FC0\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Aug 2012 14:52:09 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 EeTDFi46zCvY for <notmuch@notmuchmail.org>;\r
+ Fri, 3 Aug 2012 14:52:07 -0700 (PDT)\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 66127431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Aug 2012 14:52:06 -0700 (PDT)\r
+Received: by mail-lpp01m010-f53.google.com with SMTP id u2so681800lag.26\r
+ for <notmuch@notmuchmail.org>; Fri, 03 Aug 2012 14:52:06 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
+ :in-reply-to:references:mime-version:content-type\r
+ :content-transfer-encoding:x-gm-message-state;\r
+ bh=Xz4EV6zcUuunFx+642pEKaTQoStHEO8PJ07uzI+eTQU=;\r
+ b=GM+/dAyhmjMurc/AIW8njEoWj6DUi9gNmevKGxp5FnRkqBJ8ItlqoaEv4HLVb09aMo\r
+ f78rFOhfeItt3QCm6gM0AkbWXVYMyajlJLaVaNRTnAvJovhuAy1RrGdrtJiuE58RQ85U\r
+ nZ743ONUvPCXTgqNXcRXaMxVDWJEf0eQxbDEr1+zmaQDfgu5esV0ajG5HFSe6CAtQ9nb\r
+ ZyXxVSDH6Sip+YrT+Vh/oZuT006D4kwmCcaHsYqxX7KnWF+FzElyz0LfbTUVBNCHgvmV\r
+ 2k8/SGDJIKhQAHHAFXBZdFsrzO2UCrGb4qK7meeJ4ahhwaaZQWqj+bgNkOppoDFZIiQ3\r
+ VCWw==\r
+Received: by 10.112.46.166 with SMTP id w6mr1202283lbm.100.1344030725959;\r
+ Fri, 03 Aug 2012 14:52:05 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id jj5sm9743671lab.1.2012.08.03.14.52.04\r
+ (version=SSLv3 cipher=OTHER); Fri, 03 Aug 2012 14:52:05 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/7] test: add new test tool parse-time for date/time parser\r
+Date: Sat, 4 Aug 2012 00:51:48 +0300\r
+Message-Id:\r
+ <6ef33295de46833913336b9e5be8b8f4845f6394.1344028781.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.9.5\r
+In-Reply-To: <cover.1344028781.git.jani@nikula.org>\r
+References: <cover.1344028781.git.jani@nikula.org>\r
+In-Reply-To: <cover.1344028781.git.jani@nikula.org>\r
+References: <cover.1344028781.git.jani@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-Gm-Message-State:\r
+ ALoCoQmO2UkdKDWCdOzrfxKWAige6IlcBzWyRmv+75Q28csnzk2RIDMmFg2V9ytwRW7TusiT7ajn\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: Fri, 03 Aug 2012 21:52:09 -0000\r
+\r
+Add a tool to support testing the date/time parser module directly and\r
+independent of the rest of notmuch.\r
+---\r
+ test/Makefile.local | 9 +++-\r
+ test/basic | 2 +-\r
+ test/parse-time.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 3 files changed, 153 insertions(+), 3 deletions(-)\r
+ create mode 100644 test/parse-time.c\r
+\r
+diff --git a/test/Makefile.local b/test/Makefile.local\r
+index 4a6a4b1..729f38e 100644\r
+--- a/test/Makefile.local\r
++++ b/test/Makefile.local\r
+@@ -19,9 +19,13 @@ $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
+ $(dir)/symbol-test: $(dir)/symbol-test.o\r
+ $(call quiet,CXX) $^ -o $@ -Llib -lnotmuch -lxapian\r
+ \r
++$(dir)/parse-time: $(dir)/parse-time.o lib/parse-time-string.o\r
++ $(call quiet,CC) $^ -o $@\r
++\r
+ .PHONY: test check\r
+ \r
+-test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
++test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
++ $(dir)/parse-time\r
+ \r
+ test: all test-binaries\r
+ @${dir}/notmuch-test $(OPTIONS)\r
+@@ -31,4 +35,5 @@ check: test\r
+ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
+ CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
+ $(dir)/symbol-test $(dir)/symbol-test.o \\r
+- $(dir)/arg-test $(dir)/arg-test.o\r
++ $(dir)/arg-test $(dir)/arg-test.o \\r
++ $(dir)/parse-time $(dir)/parse-time.o\r
+diff --git a/test/basic b/test/basic\r
+index d6aed24..c658b95 100755\r
+--- a/test/basic\r
++++ b/test/basic\r
+@@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
+ eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
+ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
+ available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -executable -printf '%f\n' | \\r
+- sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
++ sed -r -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|parse-time)$/d" | \\r
+ sort)\r
+ test_expect_equal "$tests_in_suite" "$available"\r
+ \r
+diff --git a/test/parse-time.c b/test/parse-time.c\r
+new file mode 100644\r
+index 0000000..b4de76b\r
+--- /dev/null\r
++++ b/test/parse-time.c\r
+@@ -0,0 +1,145 @@\r
++/*\r
++ * parse time string - user friendly date and time parser\r
++ * Copyright © 2012 Jani Nikula\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 2 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
++ *\r
++ * Author: Jani Nikula <jani@nikula.org>\r
++ */\r
++\r
++#include <getopt.h>\r
++#include <stdio.h>\r
++#include <stdlib.h>\r
++#include <string.h>\r
++\r
++#include "parse-time-string.h"\r
++\r
++/*\r
++ * concat argv[start]...argv[end - 1], separating them by a single\r
++ * space, to a malloced string\r
++ */\r
++static char *\r
++concat_args (int start, int end, char *argv[])\r
++{\r
++ int i;\r
++ size_t len = 1;\r
++ char *p;\r
++\r
++ for (i = start; i < end; i++)\r
++ len += strlen (argv[i]) + 1;\r
++\r
++ p = malloc (len);\r
++ if (!p)\r
++ return NULL;\r
++\r
++ *p = 0;\r
++\r
++ for (i = start; i < end; i++) {\r
++ if (i != start)\r
++ strcat (p, " ");\r
++ strcat (p, argv[i]);\r
++ }\r
++\r
++ return p;\r
++}\r
++\r
++#define DEFAULT_FORMAT "%a %b %d %T %z %Y"\r
++\r
++static void\r
++usage (const char *name)\r
++{\r
++ printf ("Usage: %s [options ...] <date/time>\n\n", name);\r
++ printf (\r
++ "Parse <date/time> and display it in given format.\n\n"\r
++ " -f, --format=FMT output format, FMT according to strftime(3)\n"\r
++ " (default: \"%s\")\n"\r
++ " -n, --now=N use N seconds since epoch as now (default: now)\n"\r
++ " -u, --up round result up (default: no rounding)\n"\r
++ " -d, --down round result down (default: no rounding)\n"\r
++ " -h, --help print this help\n",\r
++ DEFAULT_FORMAT);\r
++}\r
++\r
++int\r
++main (int argc, char *argv[])\r
++{\r
++ int r;\r
++ struct tm tm;\r
++ time_t result;\r
++ time_t now;\r
++ time_t *nowp = NULL;\r
++ char *argstr;\r
++ int round = PARSE_TIME_NO_ROUND;\r
++ char buf[1024];\r
++ const char *format = DEFAULT_FORMAT;\r
++ struct option options[] = {\r
++ { "help", no_argument, NULL, 'h' },\r
++ { "up", no_argument, NULL, 'u' },\r
++ { "down", no_argument, NULL, 'd' },\r
++ { "format", required_argument, NULL, 'f' },\r
++ { "now", required_argument, NULL, 'n' },\r
++ { NULL, 0, NULL, 0 },\r
++ };\r
++\r
++ for (;;) {\r
++ int c;\r
++\r
++ c = getopt_long (argc, argv, "hudf:n:", options, NULL);\r
++ if (c == -1)\r
++ break;\r
++\r
++ switch (c) {\r
++ case 'f':\r
++ /* output format */\r
++ format = optarg;\r
++ break;\r
++ case 'u':\r
++ round = PARSE_TIME_ROUND_UP;\r
++ break;\r
++ case 'd':\r
++ round = PARSE_TIME_ROUND_DOWN;\r
++ break;\r
++ case 'n':\r
++ /* specify now in seconds since epoch */\r
++ now = (time_t) strtol (optarg, NULL, 10);\r
++ if (now >= (time_t) 0)\r
++ nowp = &now;\r
++ break;\r
++ case 'h':\r
++ case '?':\r
++ default:\r
++ usage (argv[0]);\r
++ return 1;\r
++ }\r
++ }\r
++\r
++ argstr = concat_args (optind, argc, argv);\r
++ if (!argstr)\r
++ return 1;\r
++\r
++ r = parse_time_string (argstr, &result, nowp, round);\r
++\r
++ free (argstr);\r
++\r
++ if (r)\r
++ return 1;\r
++\r
++ if (!localtime_r (&result, &tm))\r
++ return 1;\r
++\r
++ strftime (buf, sizeof (buf), format, &tm);\r
++ printf ("%s\n", buf);\r
++\r
++ return 0;\r
++}\r
+-- \r
+1.7.9.5\r
+\r