Use date_sec_change() for adding day deltas

Fixes tests range-002.sh and search-001.sh.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2015-02-22 11:32:20 +01:00
parent a6c73232a8
commit 7a631b2b63
2 changed files with 9 additions and 10 deletions

View File

@ -252,7 +252,7 @@ static void next_arg(void)
const long current_time = now(); const long current_time = now();
int time_left, hours_left, min_left; int time_left, hours_left, min_left;
next_app.time = current_time + DAYINSEC; next_app.time = date_sec_change(current_time, 0, 1);
next_app.got_app = 0; next_app.got_app = 0;
next_app.txt = NULL; next_app.txt = NULL;
@ -297,7 +297,7 @@ date_arg_from_to(long from, long to, int add_line, const char *fmt_apt,
{ {
long date; long date;
for (date = from; date < to; date += DAYINSEC) { for (date = from; date < to; date = date_sec_change(date, 0, 1)) {
day_store_items(date, 0); day_store_items(date, 0);
if (day_item_count(0) == 0) if (day_item_count(0) == 0)
continue; continue;
@ -729,9 +729,9 @@ int parse_args(int argc, char **argv)
} }
if (to == -1 && range == -1) if (to == -1 && range == -1)
to = from + DAYINSEC; to = date_sec_change(from, 0, 1);
else if (to == -1 && range >= 0) else if (to == -1 && range >= 0)
to = from + range * DAYINSEC; to = date_sec_change(from, 0, range);
else if (to >= 0 && range >= 0) else if (to >= 0 && range >= 0)
EXIT_IF(to >= 0, _("cannot specify a range and an end date")); EXIT_IF(to >= 0, _("cannot specify a range and an end date"));

View File

@ -665,9 +665,7 @@ static void get_weekday_ymd(int *year, int *month, int *day, int weekday)
localtime_r(&t, &tm); localtime_r(&t, &tm);
delta = weekday - tm.tm_wday; delta = weekday - tm.tm_wday;
if (delta <= 0) t = date_sec_change(t, 0, delta > 0 ? delta : 7);
delta += 7;
t += delta * DAYINSEC;
localtime_r(&t, &tm); localtime_r(&t, &tm);
*day = tm.tm_mday; *day = tm.tm_mday;
@ -712,10 +710,10 @@ parse_date(const char *date_string, enum datefmt datefmt, int *year,
get_ymd(year, month, day, get_today()); get_ymd(year, month, day, get_today());
return 1; return 1;
} else if (!strcasecmp(date_string, "yesterday")) { } else if (!strcasecmp(date_string, "yesterday")) {
get_ymd(year, month, day, get_today() - DAYINSEC); get_ymd(year, month, day, date_sec_change(get_today(), 0, -1));
return 1; return 1;
} else if (!strcasecmp(date_string, "tomorrow")) { } else if (!strcasecmp(date_string, "tomorrow")) {
get_ymd(year, month, day, get_today() + DAYINSEC); get_ymd(year, month, day, date_sec_change(get_today(), 0, 1));
return 1; return 1;
} else if (!strcasecmp(date_string, "now")) { } else if (!strcasecmp(date_string, "now")) {
get_ymd(year, month, day, now()); get_ymd(year, month, day, now());
@ -1290,13 +1288,14 @@ static void print_date(long date, long day, const char *extformat)
if (!strcmp(extformat, "epoch")) { if (!strcmp(extformat, "epoch")) {
printf("%ld", date); printf("%ld", date);
} else { } else {
time_t day_end = date_sec_change(day, 0, 1);
time_t t = date; time_t t = date;
struct tm lt; struct tm lt;
localtime_r((time_t *) & t, &lt); localtime_r((time_t *) & t, &lt);
if (extformat[0] == '\0' || !strcmp(extformat, "default")) { if (extformat[0] == '\0' || !strcmp(extformat, "default")) {
if (date >= day && date <= day + DAYINSEC) if (date >= day && date <= day_end)
strftime(buf, BUFSIZ, "%H:%M", &lt); strftime(buf, BUFSIZ, "%H:%M", &lt);
else else
strftime(buf, BUFSIZ, "..:..", &lt); strftime(buf, BUFSIZ, "..:..", &lt);