summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-11-15 20:05:08 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-01-07 16:57:51 +0100
commit4ba2cc46d74a3b516046d1da565e4abb4dc1b196 (patch)
treea4398251db85d6dfefdeb642765a7fcd0e792469
parent42e296c8403e52e46abb5fea70b65ae40a0425f3 (diff)
downloadcalcurse-4ba2cc46d74a3b516046d1da565e4abb4dc1b196.tar.gz
calcurse-4ba2cc46d74a3b516046d1da565e4abb4dc1b196.zip
CLI: time assignments for filter options
Explanation. There is an important difference between "to <date>" (e.g. to 15/11/2018) and "to <date time>" (e.g. to "15/11/2018 13:30"): <date> is a time span (of 24 hours), while <date time> is a point in time. "To <date>" really means "to the end of <date>", while "before <date>" means "before the beginning of <date>". There are 24 hours between the two, whereas there is only one second between "before <date time>" and "to <date time>". Similar for from/after. An earlier commit introduced parse_datearg() that only accepts a date without a time. Hence, a date should be treated as a time span from midnight to one second before next midnight. The commit also fixes an error detection bug (filter.start_from/to and filter.end_from/to were updated too early). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/args.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/args.c b/src/args.c
index 69fe977..20d3659 100644
--- a/src/args.c
+++ b/src/args.c
@@ -315,6 +315,8 @@ static int parse_daterange(const char *str, time_t *date_from, time_t *date_to)
*date_to = parse_datearg(p);
if (*date_to == -1)
goto cleanup;
+ /* One second before next midnight. */
+ *date_to = date_sec_change(*date_to, 0, 1) - 1;
} else {
*date_to = -1;
}
@@ -604,7 +606,9 @@ int parse_args(int argc, char **argv)
filter.regex = &reg;
filter_opt = 1;
break;
+ /* Assume that the date argument is midnight of the given day. */
case OPT_FILTER_START_FROM:
+ /* Midnight. */
filter.start_from = parse_datearg(optarg);
EXIT_IF(filter.start_from == -1,
_("invalid date: %s"), optarg);
@@ -614,18 +618,24 @@ int parse_args(int argc, char **argv)
filter.start_to = parse_datearg(optarg);
EXIT_IF(filter.start_to == -1,
_("invalid date: %s"), optarg);
+ /* Next midnight less one second. */
+ filter.start_to = date_sec_change(filter.start_to, 0, 1) - 1;
filter_opt = 1;
break;
case OPT_FILTER_START_AFTER:
- filter.start_from = parse_datearg(optarg) + 1;
+ filter.start_from = parse_datearg(optarg);
EXIT_IF(filter.start_from == -1,
_("invalid date: %s"), optarg);
+ /* Next midnight (belongs to the next day). */
+ filter.start_from = date_sec_change(filter.start_from, 0, 1);
filter_opt = 1;
break;
case OPT_FILTER_START_BEFORE:
- filter.start_to = parse_datearg(optarg) - 1;
+ filter.start_to = parse_datearg(optarg);
EXIT_IF(filter.start_to == -1,
_("invalid date: %s"), optarg);
+ /* One second before midnight. */
+ filter.start_to--;
filter_opt = 1;
break;
case OPT_FILTER_START_RANGE:
@@ -635,6 +645,7 @@ int parse_args(int argc, char **argv)
filter_opt = 1;
break;
case OPT_FILTER_END_FROM:
+ /* Midnight. */
filter.end_from = parse_datearg(optarg);
EXIT_IF(filter.end_from == -1,
_("invalid date: %s"), optarg);
@@ -644,18 +655,24 @@ int parse_args(int argc, char **argv)
filter.end_to = parse_datearg(optarg);
EXIT_IF(filter.end_to == -1,
_("invalid date: %s"), optarg);
+ /* Next midnight less one second. */
+ filter.end_to = date_sec_change(filter.end_to, 0, 1) - 1;
filter_opt = 1;
break;
case OPT_FILTER_END_AFTER:
- filter.end_from = parse_datearg(optarg) + 1;
+ filter.end_from = parse_datearg(optarg);
EXIT_IF(filter.end_from == -1,
_("invalid date: %s"), optarg);
+ /* Next midnight (belongs to the next day). */
+ filter.end_from = date_sec_change(filter.end_from, 0, 1);
filter_opt = 1;
break;
case OPT_FILTER_END_BEFORE:
- filter.end_to = parse_datearg(optarg) - 1;
+ filter.end_to = parse_datearg(optarg);
EXIT_IF(filter.end_to == -1,
_("invalid date: %s"), optarg);
+ /* One second before midnight. */
+ filter.end_to--;
filter_opt = 1;
break;
case OPT_FILTER_END_RANGE: