From: Peter Ujfalusi Date: Tue, 6 Sep 2022 07:04:36 +0000 (+0300) Subject: lib/timeutils: Add %s (seconds since the Epoch) to parse_timestamp() X-Git-Tag: v2.39-rc1~531 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=80e9e8ca9bba6dfd0884e0d7707d398c2ac9101d;p=thirdparty%2Futil-linux.git lib/timeutils: Add %s (seconds since the Epoch) to parse_timestamp() The %s comes handy with for example dmesg with the --since within scripts to handle log rages. Signed-off-by: Peter Ujfalusi --- diff --git a/lib/timeutils.c b/lib/timeutils.c index 2e28ada8bc..6dda2e8dee 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -181,6 +181,7 @@ int parse_timestamp(const char *t, usec_t *usec) * * 2012-09-22 16:34:22 * 2012-09-22T16:34:22 + * 1348331662 (seconds since the Epoch (1970-01-01 00:00 UTC)) * 2012-09-22 16:34 (seconds will be set to 0) * 2012-09-22 (time will be set to 00:00:00) * 16:34:22 (date will be set to today) @@ -325,6 +326,13 @@ int parse_timestamp(const char *t, usec_t *usec) goto finish; } + tm = copy; + k = strptime(t, "%s", &tm); + if (k && *k == 0) { + tm.tm_sec = 0; + goto finish; + } + return -EINVAL; finish: