commit: c701892114d5b3eea773ff13f013f4d3a71fa571 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Fri Mar 29 16:31:50 2019 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Fri Mar 29 16:31:50 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c7018921
qlop: support standard date output format in parse_date This allows to cut 'n' paste dates to limit output. Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> man/include/qlop.optdesc.yaml | 3 +++ man/qlop.1 | 5 ++++- qlop.c | 14 +++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/man/include/qlop.optdesc.yaml b/man/include/qlop.optdesc.yaml index a8fae61..25143b2 100644 --- a/man/include/qlop.optdesc.yaml +++ b/man/include/qlop.optdesc.yaml @@ -13,6 +13,9 @@ date: | .IP YYYY-MM-DD Big-endian date, with components separated by hyphens, starting with year, followed by month and day of month. + .IP YYYY-MM-DDThh:mm:ss + As before, but hours, minutes and seconds added. This is the same + format qlop prints for timestamps. .IP SSSSSSSSS Seconds since 1970-01-01 00:00:00 +0000 (UTC), the UNIX epoch. .IP FORMAT|DATE diff --git a/man/qlop.1 b/man/qlop.1 index 407c9ea..f0ef69a 100644 --- a/man/qlop.1 +++ b/man/qlop.1 @@ -1,5 +1,5 @@ .\" generated by mkman.py, please do NOT edit! -.TH qlop "1" "Feb 2019" "Gentoo Foundation" "qlop" +.TH qlop "1" "Mar 2019" "Gentoo Foundation" "qlop" .SH NAME qlop \- emerge log analyzer .SH SYNOPSIS @@ -89,6 +89,9 @@ 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. +.IP YYYY-MM-DDThh:mm:ss +As before, but hours, minutes and seconds added. This is the same +format qlop prints for timestamps. .IP SSSSSSSSS Seconds since 1970-01-01 00:00:00 +0000 (UTC), the UNIX epoch. .IP FORMAT|DATE diff --git a/qlop.c b/qlop.c index b6970d0..a87cc5c 100644 --- a/qlop.c +++ b/qlop.c @@ -103,17 +103,21 @@ parse_date(const char *sdate, time_t *t) return false; } else { /* Handle automatic formats: - * - "12315128" -> %s - * - "2015-12-24" -> %Y-%m-%d + * - "12315128" -> %s + * - "2015-12-24" -> %Y-%m-%d + * - "2019-03-28T13:52:31" -> %Y-%m-%dT%H:%M:%s" * - human readable format (see below) */ - size_t len = strspn(sdate, "0123456789-"); + size_t len = strspn(sdate, "0123456789-:T"); if (sdate[len] == '\0') { const char *fmt; - if (strchr(sdate, '-') == NULL) + if (strchr(sdate, '-') == NULL) { fmt = "%s"; - else + } else if ((s = strchr(sdate, 'T')) == NULL) { fmt = "%Y-%m-%d"; + } else { + fmt = "%Y-%m-%dT%H:%M:%S"; + } s = strptime(sdate, fmt, &tm); if (s == NULL || s[0] != '\0')