[PATCH 3/4] Use the time/date parser for after: and before: prefixes
Michal Sojka
sojkam1 at fel.cvut.cz
Sun Jan 23 03:47:26 PST 2011
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 <iostream>
@@ -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
More information about the notmuch
mailing list