1 /* parse-time-vrp.cc - date range query glue
3 * This file is part of notmuch.
5 * Copyright © 2012 Jani Nikula
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see http://www.gnu.org/licenses/ .
20 * Author: Jani Nikula <jani@nikula.org>
23 #include "database-private.h"
24 #include "parse-time-vrp.h"
25 #include "parse-time-string.h"
27 #define PREFIX "date:"
29 /* See *ValueRangeProcessor in xapian-core/api/valuerangeproc.cc */
31 ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)
35 /* Require date: prefix in start of the range... */
36 if (STRNCMP_LITERAL (begin.c_str (), PREFIX))
37 return Xapian::BAD_VALUENO;
39 /* ...and remove it. */
40 begin.erase (0, sizeof (PREFIX) - 1);
42 /* Use the same 'now' for begin and end. */
43 if (time (&now) == (time_t) -1)
44 return Xapian::BAD_VALUENO;
46 if (!begin.empty ()) {
47 if (parse_time_string (begin.c_str (), &t, &now, PARSE_TIME_ROUND_DOWN))
48 return Xapian::BAD_VALUENO;
50 begin.assign (Xapian::sortable_serialise ((double) t));
54 if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))
55 return Xapian::BAD_VALUENO;
57 end.assign (Xapian::sortable_serialise ((double) t));