aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/time-stamp.el8
-rw-r--r--test/lisp/time-stamp-tests.el23
2 files changed, 24 insertions, 7 deletions
diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 6b1ff3e618c..55892cdb83c 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -570,11 +570,13 @@ and all `time-stamp-format' compatibility."
570 (string-to-number (time-stamp--format "%Y" time))))) 570 (string-to-number (time-stamp--format "%Y" time)))))
571 ((eq cur-char ?Y) ;4-digit year 571 ((eq cur-char ?Y) ;4-digit year
572 (string-to-number (time-stamp--format "%Y" time))) 572 (string-to-number (time-stamp--format "%Y" time)))
573 ((eq cur-char ?z) ;time zone lower case 573 ((eq cur-char ?z) ;time zone offset
574 (if change-case 574 (if change-case
575 "" ;discourage %z variations 575 "" ;discourage %z variations
576 (time-stamp--format "%#Z" time))) 576 (if alt-form
577 ((eq cur-char ?Z) 577 (time-stamp--format "%z" time)
578 (time-stamp--format "%#Z" time)))) ;backward compat, will change
579 ((eq cur-char ?Z) ;time zone name
578 (if change-case 580 (if change-case
579 (time-stamp--format "%#Z" time) 581 (time-stamp--format "%#Z" time)
580 (time-stamp--format "%Z" time))) 582 (time-stamp--format "%Z" time)))
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index ad2cb0ead7f..77cd6c5b945 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -299,18 +299,33 @@
299 (should (equal (time-stamp-string "%w" ref-time2) "5")) 299 (should (equal (time-stamp-string "%w" ref-time2) "5"))
300 (should (equal (time-stamp-string "%w" ref-time3) "0")))) 300 (should (equal (time-stamp-string "%w" ref-time3) "0"))))
301 301
302(ert-deftest time-stamp-test-format-time-zone () 302(ert-deftest time-stamp-test-format-time-zone-name ()
303 "Test time-stamp formats for time zone." 303 "Test time-stamp format %Z."
304 (with-time-stamp-test-env 304 (with-time-stamp-test-env
305 (let ((UTC-abbr (format-time-string "%Z" ref-time1 t)) 305 (let ((UTC-abbr (format-time-string "%Z" ref-time1 t))
306 (utc-abbr (format-time-string "%#Z" ref-time1 t))) 306 (utc-abbr (format-time-string "%#Z" ref-time1 t)))
307 ;; implemented and documented since 1995 307 ;; implemented and documented since 1995
308 (should (equal (time-stamp-string "%Z" ref-time1) UTC-abbr)) 308 (should (equal (time-stamp-string "%Z" ref-time1) UTC-abbr))
309 ;; documented 1995-2019
310 (should (equal (time-stamp-string "%z" ref-time1) utc-abbr))
311 ;; implemented since 1997, documented since 2019 309 ;; implemented since 1997, documented since 2019
312 (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr))))) 310 (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr)))))
313 311
312(ert-deftest time-stamp-test-format-time-zone-offset ()
313 "Test time-stamp format %z."
314 (with-time-stamp-test-env
315 ;; documented 1995-2019, will change
316 (should (equal (time-stamp-string "%z" ref-time1)
317 (format-time-string "%#Z" ref-time1 t)))
318 ;; undocumented, changed in 2019
319 (should (equal (time-stamp-string "%:z" ref-time1) "+0000"))
320 (should (equal (time-stamp-string "%:7z" ref-time1) " +0000"))
321 (should (equal (time-stamp-string "%:07z" ref-time1) " +0000"))
322 (let ((time-stamp-time-zone "PST8"))
323 (should (equal (time-stamp-string "%:z" ref-time1) "-0800")))
324 (let ((time-stamp-time-zone "HST10"))
325 (should (equal (time-stamp-string "%:z" ref-time1) "-1000")))
326 (let ((time-stamp-time-zone "CET-1"))
327 (should (equal (time-stamp-string "%:z" ref-time1) "+0100")))))
328
314(ert-deftest time-stamp-test-format-non-date-conversions () 329(ert-deftest time-stamp-test-format-non-date-conversions ()
315 "Test time-stamp formats for non-date items." 330 "Test time-stamp formats for non-date items."
316 (with-time-stamp-test-env 331 (with-time-stamp-test-env