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>
This commit is contained in:
parent
4285e88593
commit
03880a82bf
14
src/args.c
14
src/args.c
@ -249,7 +249,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 = date_sec_change(date, 0, 1)) {
|
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;
|
||||||
@ -713,18 +713,16 @@ int parse_args(int argc, char **argv)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIT_IF(to >= 0 && range > 0, _("cannot specify a range and an end date"));
|
EXIT_IF(to >= 0 && range, _("cannot specify a range and an end date"));
|
||||||
EXIT_IF(from >= 0 && range < 0, _("cannot specify a negative range and a start date"));
|
|
||||||
|
|
||||||
if (from == -1)
|
if (from == -1)
|
||||||
from = get_today();
|
from = get_today();
|
||||||
if (to == -1)
|
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)
|
if (range > 0)
|
||||||
to = date_sec_change(from, 0, range);
|
to = date_sec_change(from, 0, range - 1);
|
||||||
else if (range < 0)
|
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_init(cfile, datadir, confdir);
|
||||||
io_check_dir(path_ddir);
|
io_check_dir(path_ddir);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user