]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/timeutils: Add %s (seconds since the Epoch) to parse_timestamp()
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Tue, 6 Sep 2022 07:04:36 +0000 (10:04 +0300)
committerKarel Zak <kzak@redhat.com>
Tue, 6 Sep 2022 08:46:09 +0000 (10:46 +0200)
The %s comes handy with for example dmesg with the --since within scripts
to handle log rages.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
lib/timeutils.c

index 2e28ada8bc47a143de7aeca7b801b6bf8a36f92c..6dda2e8deefbea3d0c2bf956a9c5dc6f2ae17879 100644 (file)
@@ -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: