]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl -o short-iso[-precise]: timezone as +02:00 instead of +0200 29134/head
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Fri, 8 Sep 2023 15:28:57 +0000 (17:28 +0200)
committerнаб <nabijaczleweli@nabijaczleweli.xyz>
Tue, 26 Sep 2023 13:24:13 +0000 (15:24 +0200)
man/journalctl.xml
src/shared/logs-show.c

index 9054cc8ded0ce64fff819b56e6e46c7144e2da24..8ac540084170ea0994dff98c25badcd217b3b74f 100644 (file)
 
           <varlistentry>
             <term><option>short-iso</option></term>
-            <listitem><para>is very similar, but shows ISO 8601 wallclock timestamps.</para>
+            <listitem><para>is very similar, but shows timestamps in the
+            <ulink url="https://tools.ietf.org/html/rfc3339">RFC 3339</ulink> profile of ISO 8601.</para>
 
             <xi:include href="version-info.xml" xpointer="v206"/></listitem>
           </varlistentry>
index abe11b817c80edbccc30617bf63340ddd1a36ac4..deceea5da991867e64c5101248eb687524f58a60 100644 (file)
@@ -403,24 +403,25 @@ static int output_timestamp_realtime(
                         break;
 
                 case OUTPUT_SHORT_ISO:
-                        if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z",
-                                     localtime_or_gmtime_r(&t, &tm, flags & OUTPUT_UTC)) <= 0)
+                case OUTPUT_SHORT_ISO_PRECISE: {
+                        size_t tail = strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S",
+                                               localtime_or_gmtime_r(&t, &tm, flags & OUTPUT_UTC));
+                        if (tail == 0)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "Failed to format ISO time");
-                        break;
 
-                case OUTPUT_SHORT_ISO_PRECISE: {
-                        char usec[7];
+                        /* No usec in strftime, need to append */
+                        if (mode == OUTPUT_SHORT_ISO_PRECISE) {
+                                snprintf(buf + tail, ELEMENTSOF(buf) - tail, ".%06"PRI_USEC, display_ts->realtime % USEC_PER_SEC);
+                                tail += 7;
+                        }
 
-                        /* No usec in strftime, so we leave space and copy over */
-                        if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.xxxxxx%z",
-                                     localtime_or_gmtime_r(&t, &tm, flags & OUTPUT_UTC)) <= 0)
-                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                       "Failed to format ISO-precise time");
-                        xsprintf(usec, "%06"PRI_USEC, display_ts->realtime % USEC_PER_SEC);
-                        memcpy(buf + 20, usec, 6);
+                        int8_t h = tm.tm_gmtoff / 60 / 60;
+                        int8_t m = labs((tm.tm_gmtoff / 60) % 60);
+                        snprintf(buf + tail, ELEMENTSOF(buf) - tail, "%+03"PRId8":%02"PRId8, h, m);
                         break;
                 }
+
                 case OUTPUT_SHORT:
                 case OUTPUT_SHORT_PRECISE: