]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: support parsing OUTPUT_SHORT and OUTPUT_SHORT_PRECISE timestamps
authorFrantisek Sumsal <frantisek@sumsal.cz>
Sat, 12 Mar 2022 11:17:46 +0000 (12:17 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 12 Mar 2022 17:18:08 +0000 (17:18 +0000)
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

src/basic/time-util.c
src/test/test-date.c

index 590e2e9e08a3d78e8265cb062d7078df9f7d484a..ebf1dddb569432e9bfe520cde80a69d7bb32806b 100644 (file)
@@ -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) {
index 355f4e17de5d99cff148fa5c8ab27606453825b1..b3b902e64bd067ae6e1cdc85456c558b10898329 100644 (file)
@@ -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");