--- /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 DD2ED431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Aug 2012 00:42:10 -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 asFfUgzl7tso for <notmuch@notmuchmail.org>;\r
+ Sat, 4 Aug 2012 00:42:09 -0700 (PDT)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+ [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D1A93431FC2\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Aug 2012 00:42:08 -0700 (PDT)\r
+Received: by mail-lb0-f181.google.com with SMTP id gk1so786230lbb.26\r
+ for <notmuch@notmuchmail.org>; Sat, 04 Aug 2012 00:42:08 -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=3tRyV5jvHcPOsy5qBBZ+38CHml22Cu0A+pplzBiWVxU=;\r
+ b=MaVAWYNU8OxAR5H/1w9Qd2QpzCDVCmZtoREhduBCKdjYpZmH4S3u3xSk2KOmx/XXJ0\r
+ fhy76y0cJGENII5T5WcVQOS61kdSoyQObe9ah6REnXs9+tS5cOsLWyjTq7hDXqTUlNvl\r
+ X2DdkxNcqNJoHfvHvdMzPmkRs8qgxX7yGH4VY3HBubZmjs8rTppg6WrM1W9afpiQEF2n\r
+ x6udSVs5WWQsch9EiL++kXiAgRxUoVrdI3Zb4m/oxNfeivmXCrBnMH2LgsZkx70xpBnE\r
+ cX8Gk2UzfPBKT6nH5TlSeq70q3nyGnn4ZsVokizefgSQ5y9Pl6MCAjyYvmqjcQGfW4fy\r
+ V/bg==\r
+Received: by 10.152.148.1 with SMTP id to1mr3969243lab.34.1344066128314;\r
+ Sat, 04 Aug 2012 00:42:08 -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 jj5sm10847268lab.1.2012.08.04.00.42.06\r
+ (version=SSLv3 cipher=OTHER); Sat, 04 Aug 2012 00:42:07 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject:\r
+ [PATCH v2 3/7] test: add new test tool parse-time for date/time parser\r
+Date: Sat, 4 Aug 2012 10:41:41 +0300\r
+Message-Id:\r
+ <d5416c5b6fd59e8458a7fab83b98b0c4803b47c9.1344065790.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.9.5\r
+In-Reply-To: <cover.1344065790.git.jani@nikula.org>\r
+References: <cover.1344065790.git.jani@nikula.org>\r
+In-Reply-To: <cover.1344065790.git.jani@nikula.org>\r
+References: <cover.1344065790.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
+ ALoCoQmOalWiV+Vr4jjCtMI7RvTfXKMADn24eCDide4yvBcqzA5p7Y8QwpvKkpkRX3zl03925HAH\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: Sat, 04 Aug 2012 07:42:11 -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 | 7 ++-\r
+ test/basic | 2 +-\r
+ test/parse-time.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 3 files changed, 152 insertions(+), 2 deletions(-)\r
+ create mode 100644 test/parse-time.c\r
+\r
+diff --git a/test/Makefile.local b/test/Makefile.local\r
+index c7f1435..1a76617 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
+@@ -32,4 +36,5 @@ 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)/parse-time $(dir)/parse-time.o \\r
+ $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\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