]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'bb/iso-strict-utc'
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Mar 2024 21:55:14 +0000 (14:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Mar 2024 21:55:14 +0000 (14:55 -0700)
The output format for dates "iso-strict" has been tweaked to show
a time in the Zulu timezone with "Z" suffix, instead of "+00:00".

* bb/iso-strict-utc:
  date: make "iso-strict" conforming for the UTC timezone

date.c
t/t0006-date.sh

diff --git a/date.c b/date.c
index 619ada5b20442046ef50a38d4e88136b14419a42..44cf2221d81f61760fa26605765eaea5eee9ee4d 100644 (file)
--- a/date.c
+++ b/date.c
@@ -342,14 +342,18 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
                                tm->tm_hour, tm->tm_min, tm->tm_sec,
                                tz);
        else if (mode->type == DATE_ISO8601_STRICT) {
-               char sign = (tz >= 0) ? '+' : '-';
-               tz = abs(tz);
-               strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",
+               strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d:%02d:%02d",
                                tm->tm_year + 1900,
                                tm->tm_mon + 1,
                                tm->tm_mday,
-                               tm->tm_hour, tm->tm_min, tm->tm_sec,
-                               sign, tz / 100, tz % 100);
+                               tm->tm_hour, tm->tm_min, tm->tm_sec);
+               if (tz == 0) {
+                       strbuf_addch(&timebuf, 'Z');
+               } else {
+                       strbuf_addch(&timebuf, tz >= 0 ? '+' : '-');
+                       tz = abs(tz);
+                       strbuf_addf(&timebuf, "%02d:%02d", tz / 100, tz % 100);
+               }
        } else if (mode->type == DATE_RFC2822)
                strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d",
                        weekday_names[tm->tm_wday], tm->tm_mday,
index e18b1602864ec432553266e89d3796e94741e8e0..1d228a981ee96471d36c173e3b0036f59d0395e2 100755 (executable)
@@ -46,6 +46,7 @@ check_show () {
 TIME='1466000000 +0200'
 check_show iso8601 "$TIME" '2016-06-15 16:13:20 +0200'
 check_show iso8601-strict "$TIME" '2016-06-15T16:13:20+02:00'
+check_show iso8601-strict "$(echo "$TIME" | sed 's/+0200$/+0000/')" '2016-06-15T14:13:20Z'
 check_show rfc2822 "$TIME" 'Wed, 15 Jun 2016 16:13:20 +0200'
 check_show short "$TIME" '2016-06-15'
 check_show default "$TIME" 'Wed Jun 15 16:13:20 2016 +0200'