From: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
To: kzak@redhat.com
Cc: util-linux@vger.kernel.org, peter.ujfalusi@linux.intel.com
Subject: [PATCH] lib/timeutils: Add %s (seconds since the Epoch) to parse_timestamp()
Date: Tue, 6 Sep 2022 10:04:36 +0300 [thread overview]
Message-ID: <20220906070436.684-1-peter.ujfalusi@linux.intel.com> (raw)
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 | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/timeutils.c b/lib/timeutils.c
index 2e28ada8bc47..6dda2e8deefb 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:
--
2.37.3
next reply other threads:[~2022-09-06 7:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 7:04 Peter Ujfalusi [this message]
2022-09-06 8:47 ` [PATCH] lib/timeutils: Add %s (seconds since the Epoch) to parse_timestamp() Karel Zak
2022-09-06 16:31 ` Péter Ujfalusi
2022-09-07 7:20 ` Karel Zak
2022-09-07 12:57 ` Dmitry V. Levin
2022-09-08 9:29 ` Péter Ujfalusi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220906070436.684-1-peter.ujfalusi@linux.intel.com \
--to=peter.ujfalusi@linux.intel.com \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox