* lib: mu date: better handling of date fields in newer xapians
This commit is contained in:
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
#include "mu-date.h"
|
#include "mu-date.h"
|
||||||
|
#include "mu-str.h"
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_date_str_s (const char* frm, time_t t)
|
mu_date_str_s (const char* frm, time_t t)
|
||||||
@ -174,10 +175,13 @@ const char*
|
|||||||
mu_date_interpret_s (const char *datespec, gboolean is_begin)
|
mu_date_interpret_s (const char *datespec, gboolean is_begin)
|
||||||
{
|
{
|
||||||
static char fulldate[14 + 1];
|
static char fulldate[14 + 1];
|
||||||
time_t now;
|
time_t now, t;
|
||||||
|
|
||||||
g_return_val_if_fail (datespec, NULL);
|
g_return_val_if_fail (datespec, NULL);
|
||||||
|
|
||||||
|
if (mu_str_is_empty (datespec) && is_begin)
|
||||||
|
return "000000000000"; /* beginning of time*/
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
if (strcmp (datespec, "today") == 0) {
|
if (strcmp (datespec, "today") == 0) {
|
||||||
strftime(fulldate, sizeof(fulldate),
|
strftime(fulldate, sizeof(fulldate),
|
||||||
@ -186,21 +190,18 @@ mu_date_interpret_s (const char *datespec, gboolean is_begin)
|
|||||||
return fulldate;
|
return fulldate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (datespec, "now") == 0) {
|
if (mu_str_is_empty (datespec) || strcmp (datespec, "now") == 0) {
|
||||||
strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
|
strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
|
||||||
localtime(&now));
|
localtime(&now));
|
||||||
return fulldate;
|
return fulldate;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
time_t t;
|
|
||||||
t = mu_date_parse_hdwmy (datespec);
|
t = mu_date_parse_hdwmy (datespec);
|
||||||
if (t != (time_t)-1) {
|
if (t != (time_t)-1) {
|
||||||
strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
|
strftime(fulldate, sizeof(fulldate), "%Y%m%d%H%M%S",
|
||||||
localtime(&t));
|
localtime(&t));
|
||||||
return fulldate;
|
return fulldate;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return datespec; /* nothing changed */
|
return datespec; /* nothing changed */
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user