From: Frantisek Sumsal Date: Sat, 12 Mar 2022 11:17:46 +0000 (+0100) Subject: time-util: support parsing OUTPUT_SHORT and OUTPUT_SHORT_PRECISE timestamps X-Git-Tag: v251-rc1~160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=34c4dff4d2e592e90dd9833fee4ce1ac981e8ea9;p=thirdparty%2Fsystemd.git time-util: support parsing OUTPUT_SHORT and OUTPUT_SHORT_PRECISE timestamps so we can feed journalctl the localized syslog-style timestamps it shows by default, e.g.: ``` $ LANG=cs_CZ.utf-8 build-san/journalctl -b --no-hostname | head -n1 led 30 22:13:54 systemd-journald[981]: System Journal (/var/log/journal/1588e1d9d0b74acdbaada907b163b837) is 4.1G, max 4.0G, 0B free. $ LANG=cs_CZ.utf-8 build-san/journalctl --no-hostname --since 'led 30 22:13:54' -n1 led 30 22:13:54 systemd-journald[981]: System Journal (/var/log/journal/1588e1d9d0b74acdbaada907b163b837) is 4.1G, max 4.0G, 0B free. $ LANG=cs_CZ.utf-8 build-san/journalctl --no-hostname --since 'led 30 22:13:54.9999' -n1 led 30 22:13:58 rsyslogd[1300]: imjournal: journal files changed, reloading... [v8.2102.0-4.fc35 try https://www.rsyslog.com/e/0 ] ``` Resolves: #15899 --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 590e2e9e08a..ebf1dddb569 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -798,6 +798,16 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) { goto from_tm; } + /* Support OUTPUT_SHORT and OUTPUT_SHORT_PRECISE formats */ + tm = copy; + k = strptime(t, "%b %d %H:%M:%S", &tm); + if (k) { + if (*k == '.') + goto parse_usec; + else if (*k == 0) + goto from_tm; + } + tm = copy; k = strptime(t, "%y-%m-%d %H:%M", &tm); if (k && *k == 0) { diff --git a/src/test/test-date.c b/src/test/test-date.c index 355f4e17de5..b3b902e64bd 100644 --- a/src/test/test-date.c +++ b/src/test/test-date.c @@ -73,6 +73,8 @@ int main(int argc, char *argv[]) { test_one("12-10-03 12:13"); test_one("2012-12-30 18:42"); test_one("2012-10-02"); + test_one("Mar 12 12:01:01"); + test_one("Mar 12 12:01:01.687197"); test_one("Tue 2012-10-02"); test_one("yesterday"); test_one("today");