aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-11-08 10:12:38 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-01-07 16:57:43 +0100
commit03880a82bf203becaa2c8c12d75c1c16a53c0449 (patch)
tree248e2ddd1d3e03623f035f720182d0acbd8e6e33
parent4285e8859353c31b39fa9539a89e58dc3a020264 (diff)
downloadcalcurse-03880a82bf203becaa2c8c12d75c1c16a53c0449.tar.gz
calcurse-03880a82bf203becaa2c8c12d75c1c16a53c0449.zip
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 <lfleischer@calcurse.org>
-rw-r--r--src/args.c14
1 files changed, 6 insertions, 8 deletions
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);