From 03880a82bf203becaa2c8c12d75c1c16a53c0449 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Thu, 8 Nov 2018 10:12:38 +0100 Subject: Fix day range for queries In "--from a --to z", a is included in the range, z not. This is non-intuitive and disagrees with the semantics of "to" in filter options like --filter-start-to, where "to" (and "from") are used inclusively (as opposed to "before" and "after"). It also has the effect that "--from today --to tomorrow" has a range of 1 day, "--to z" a range of 0 days (otherwise not allowed), and "--to today --days -1" is allowed and displays yesterday! The implementation has been fixed to agree with "inclusive" semantics. Options --from and -days with negative range are allowed, while --to and --days are disallowed also when the range is negative. Signed-off-by: Lukas Fleischer --- src/args.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/args.c') diff --git a/src/args.c b/src/args.c index e166f5a..be77957 100644 --- a/src/args.c +++ b/src/args.c @@ -249,7 +249,7 @@ date_arg_from_to(long from, long to, int add_line, const char *fmt_apt, { long date; - for (date = from; date < to; date = date_sec_change(date, 0, 1)) { + for (date = from; date <= to; date = date_sec_change(date, 0, 1)) { day_store_items(date, 0); if (day_item_count(0) == 0) continue; @@ -713,18 +713,16 @@ int parse_args(int argc, char **argv) goto cleanup; } - EXIT_IF(to >= 0 && range > 0, _("cannot specify a range and an end date")); - EXIT_IF(from >= 0 && range < 0, _("cannot specify a negative range and a start date")); - + EXIT_IF(to >= 0 && range, _("cannot specify a range and an end date")); if (from == -1) from = get_today(); if (to == -1) - to = date_sec_change(from, 0, 1); - + to = from; + EXIT_IF(to < from, _("end date cannot come before start date")); if (range > 0) - to = date_sec_change(from, 0, range); + to = date_sec_change(from, 0, range - 1); else if (range < 0) - from = date_sec_change(to, 0, range); + from = date_sec_change(to, 0, range + 1); io_init(cfile, datadir, confdir); io_check_dir(path_ddir); -- cgit v1.2.3-54-g00ecf