commit: b5cc7d87b7adf46c2444c68537d8fcfb73ae0060 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Thu Apr 12 19:32:37 2018 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Thu Apr 12 19:32:37 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b5cc7d87
qlop: accept "today" and "yesterday" for parse_date Bug: https://bugs.gentoo.org/652312 man/include/qlop.optdesc.yaml | 4 ++++ man/qlop.1 | 4 ++++ qlop.c | 13 +++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/man/include/qlop.optdesc.yaml b/man/include/qlop.optdesc.yaml index fad1670..3ff62c3 100644 --- a/man/include/qlop.optdesc.yaml +++ b/man/include/qlop.optdesc.yaml @@ -6,6 +6,10 @@ date: | .IP "NUMBER <day|week|month|year>[s] [ago]" Relative time, specifying \fINUMBER\fR \fIdays\fR, \fIweeks\fR, \fImonths\fR or \fIyears\fR, for example \fI3 days ago\fR. + .IP today + Alias for \fI0 days ago\fR. + .IP yesterday + Alias for \fI1 day ago\fR. .IP YYYY-MM-DD Big-endian date, with components separated by hyphens, starting with year, followed by month and day of month. diff --git a/man/qlop.1 b/man/qlop.1 index 9c449a9..18c05fb 100644 --- a/man/qlop.1 +++ b/man/qlop.1 @@ -46,6 +46,10 @@ can take a few forms. .IP "NUMBER <day|week|month|year>[s] [ago]" Relative time, specifying \fINUMBER\fR \fIdays\fR, \fIweeks\fR, \fImonths\fR or \fIyears\fR, for example \fI3 days ago\fR. +.IP today +Alias for \fI0 days ago\fR. +.IP yesterday +Alias for \fI1 day ago\fR. .IP YYYY-MM-DD Big-endian date, with components separated by hyphens, starting with year, followed by month and day of month. diff --git a/qlop.c b/qlop.c index 1d4e0d9..7bac8c2 100644 --- a/qlop.c +++ b/qlop.c @@ -758,8 +758,17 @@ parse_date(const char *sdate, time_t *t) char ago[len]; int ret = sscanf(sdate, "%lu %s %s", &num, dur, ago); - if (ret < 2) - return false; + if (ret < 2) { + if (strcmp(sdate, "today") == 0) { + num = 0; + snprintf(dur, len, "%s", "day"); + } else if (strcmp(sdate, "yesterday") == 0) { + num = 1; + snprintf(dur, len, "%s", "day"); + } else { + return false; + } + } if (ret == 3 && strcmp(ago, "ago") != 0) return false;