From: Francois Fleuret Date: Tue, 5 Feb 2013 13:32:29 +0000 (+0100) Subject: Added criteria for previous week days. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=43d77e1079096fc1af9ce18e1cd2698ebfd210a4;p=mymail.git Added criteria for previous week days. --- diff --git a/mymail.c b/mymail.c index f2397a6..2519a7a 100644 --- a/mymail.c +++ b/mymail.c @@ -217,6 +217,18 @@ void print_usage(FILE *out) { /*********************************************************************/ +time_t time_for_past_day(int day) { + time_t t; + struct tm *tm; + int delta_day; + t = time(0); + tm = localtime(&t); + delta_day = (7 + tm->tm_wday - day) % 7 + 1; + return t - delta_day * 3600 * 24 + tm->tm_sec + 60 * tm->tm_min + 3600 * tm->tm_hour; +} + +/*********************************************************************/ + int ignore_entry(const char *name) { return /* strcmp(name, ".") == 0 || */ @@ -710,10 +722,52 @@ void init_condition(struct search_condition *condition, char *string) { condition->interval_stop = 0; } + else if(strcmp(search_field, "monday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(1); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "tuesday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(2); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "wednesday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(3); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "thursday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(4); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "friday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(5); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "saturday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(6); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + + else if(strcmp(search_field, "sunday") == 0) { + condition->field_id = ID_INTERVAL; + condition->interval_start = time_for_past_day(7); + condition->interval_stop = condition->interval_start + 3600 * 24; + } + else if(strcmp(search_field, "yesterday") == 0) { condition->field_id = ID_INTERVAL; condition->interval_start = time(0) - 2 * 3600 * 24; - condition->interval_stop = time(0) - 3600 * 24; + condition->interval_stop = condition->interval_start + 3600 * 24; } else {