Subject: 26.0.60; Gnus: broken timezone in citation line

From: Paul Eggert <[email-masked]>
Date: Sun, 17 Sep 2017 20:56:05 -0700

Thanks for the bug report.

I see two issues here. First, the change in message-citation-line-format's 
treatment of %Z was deliberate. The new treatment (unlike the old one) is 
consistent with format-time-string and this consistency simplifies the 
documentation and code. If backward-compatibility is a significant hassle we can 
re-complicate Emacs, but I'm hoping that users can change %Z to %z in their 
settings and move on. In the meantime I installed the first attached patch into 
the emacs-26 branch so that the documentation matches the new behavior. (Sorry, 
I missed that part of the documentation before.)

Second, (format-time-string "%Z" nil -25200) returns "+07" where it should 
return "-07" since -25200 denotes 7 hours west of UTC. This is due to a blunder 
in my commit fdb1ba144ca61185e6457f092f38f59dd9bbe6a0 dated 2016-04-12 09:19:11 
-0700: the %Z code gets the sign wrong on purely-numeric time zones west of 
Greenwich. To fix this bug I installed the second attached patch into the 
emacs-26 branch. This fix should cause your example to come out as:

   On 16 September 2017 17:18 -07, Mike Kupfer wrote:

which at least gets the sign right.
From 679e05eeb97eae5a32fc67f4673b019c873ebcca Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 17 Sep 2017 17:46:18 -0700
Subject: [PATCH 1/2] message-citation-line-format %Z is now tz name

* etc/NEWS:
* lisp/gnus/message.el (message-citation-line-format):
Fix doc to match new behavior (Bug#28476).
---
 etc/NEWS             | 6 ++++++
 lisp/gnus/message.el | 1 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index a042ce9..5aa57a7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -701,6 +701,12 @@ method is an NNTP select method.
 *** A new command for sorting articles by readedness marks has been
 added: 'C-c C-s C-m C-m'.
 
++++
+
+*** In message-citation-line-format the %Z format is now the time zone name
+instead of the numeric form.  The %z format continues to be the
+numeric form.  The new behavior is compatible with format-time-string.
+
 ** Ibuffer
 
 ---
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index 690dd28..a9e66ce 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -991,7 +991,6 @@ message-citation-line-format
   %F   The first name if present, e.g.: \"John\", else fall
        back to the mail address.
   %L   The last name if present, e.g.: \"Doe\".
-  %Z, %z   The time zone in the numeric form, e.g.:\"+0000\".
 
 All other format specifiers are passed to `format-time-string'
 which is called using the date from the article your replying to, but
-- 
2.7.4

From 74fbe646c7d735343628979f6e9bb4543f01fe52 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 17 Sep 2017 20:38:12 -0700
Subject: [PATCH 2/2] Fix format-time-string %Z bug with negative tz

* src/editfns.c (tzlookup): Fix sign error in %Z when a purely
numeric zone is negative (Bug#28746).
* test/src/editfns-tests.el (format-time-string-with-zone):
Add test for this bug.
---
 src/editfns.c             | 3 ++-
 test/src/editfns-tests.el | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/editfns.c b/src/editfns.c
index b03eb94..2f8b075 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -187,7 +187,8 @@ tzlookup (Lisp_Object zone, bool settz)
 		  if (sec != 0)
 		    prec += 2, numzone = 100 * numzone + sec;
 		}
-	      sprintf (tzbuf, tzbuf_format, prec, numzone,
+	      sprintf (tzbuf, tzbuf_format, prec,
+		       XINT (zone) < 0 ? -numzone : numzone,
 		       &"-"[XINT (zone) < 0], hour, min, sec);
 	      zone_string = tzbuf;
 	    }
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 1c3fde8..f910afa 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -166,6 +166,10 @@ transpose-test-get-byte-positions
     (should (string-equal
              (format-time-string format look '(-28800 "PST"))
              "1972-06-30 15:59:59.999 -0800 (PST)"))
+    ;; Negative UTC offset, as a Lisp integer.
+    (should (string-equal
+             (format-time-string format look -28800)
+             "1972-06-30 15:59:59.999 -0800 (-08)"))
     ;; Positive UTC offset that is not an hour multiple, as a string.
     (should (string-equal
              (format-time-string format look "IST-5:30")
-- 
2.7.4