emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ce67ba: time-stamp: add support for time zone numeric offset


From: Stephen Gildea
Subject: master 9ce67ba: time-stamp: add support for time zone numeric offset
Date: Wed, 6 Nov 2019 11:34:42 -0500 (EST)

branch: master
commit 9ce67baa9a3733ae93885b6242130497b13c8703
Author: Stephen Gildea <address@hidden>
Commit: Stephen Gildea <address@hidden>

    time-stamp: add support for time zone numeric offset
    
    * time-stamp.el: Implement %:z as expanding to the numeric time zone
    offset, to address the feature request of bug#32931.  Do not document it
    yet, to discourage compatibility problems in mixed Emacs 26 and Emacs 27
    environments.  Documentation will be added in a subsequent release at
    least two years later.  (We cannot yet use %z for numeric time zone
    because in Emacs 26 it was documented to do something else.)
    
    * time-stamp-tests.el (time-stamp-test-format-time-zone): expand this
    test and break it into two tests, time-stamp-test-format-time-zone-name
    and time-stamp-test-format-time-zone-offset.
---
 lisp/time-stamp.el            |  8 +++++---
 test/lisp/time-stamp-tests.el | 23 +++++++++++++++++++----
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el
index 6b1ff3e..55892cd 100644
--- a/lisp/time-stamp.el
+++ b/lisp/time-stamp.el
@@ -570,11 +570,13 @@ and all `time-stamp-format' compatibility."
               (string-to-number (time-stamp--format "%Y" time)))))
         ((eq cur-char ?Y)              ;4-digit year
          (string-to-number (time-stamp--format "%Y" time)))
-        ((eq cur-char ?z)              ;time zone lower case
+        ((eq cur-char ?z)              ;time zone offset
          (if change-case
              ""                        ;discourage %z variations
-           (time-stamp--format "%#Z" time)))
-        ((eq cur-char ?Z)
+            (if alt-form
+                (time-stamp--format "%z" time)
+              (time-stamp--format "%#Z" time)))) ;backward compat, will change
+        ((eq cur-char ?Z)              ;time zone name
          (if change-case
              (time-stamp--format "%#Z" time)
            (time-stamp--format "%Z" time)))
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index ad2cb0e..77cd6c5 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -299,18 +299,33 @@
     (should (equal (time-stamp-string "%w" ref-time2) "5"))
     (should (equal (time-stamp-string "%w" ref-time3) "0"))))
 
-(ert-deftest time-stamp-test-format-time-zone ()
-  "Test time-stamp formats for time zone."
+(ert-deftest time-stamp-test-format-time-zone-name ()
+  "Test time-stamp format %Z."
   (with-time-stamp-test-env
     (let ((UTC-abbr (format-time-string "%Z" ref-time1 t))
          (utc-abbr (format-time-string "%#Z" ref-time1 t)))
       ;; implemented and documented since 1995
       (should (equal (time-stamp-string "%Z" ref-time1) UTC-abbr))
-      ;; documented 1995-2019
-      (should (equal (time-stamp-string "%z" ref-time1) utc-abbr))
       ;; implemented since 1997, documented since 2019
       (should (equal (time-stamp-string "%#Z" ref-time1) utc-abbr)))))
 
+(ert-deftest time-stamp-test-format-time-zone-offset ()
+  "Test time-stamp format %z."
+  (with-time-stamp-test-env
+    ;; documented 1995-2019, will change
+    (should (equal (time-stamp-string "%z" ref-time1)
+                   (format-time-string "%#Z" ref-time1 t)))
+    ;; undocumented, changed in 2019
+    (should (equal (time-stamp-string "%:z" ref-time1) "+0000"))
+    (should (equal (time-stamp-string "%:7z" ref-time1) "  +0000"))
+    (should (equal (time-stamp-string "%:07z" ref-time1) "  +0000"))
+    (let ((time-stamp-time-zone "PST8"))
+      (should (equal (time-stamp-string "%:z" ref-time1) "-0800")))
+    (let ((time-stamp-time-zone "HST10"))
+      (should (equal (time-stamp-string "%:z" ref-time1) "-1000")))
+    (let ((time-stamp-time-zone "CET-1"))
+      (should (equal (time-stamp-string "%:z" ref-time1) "+0100")))))
+
 (ert-deftest time-stamp-test-format-non-date-conversions ()
   "Test time-stamp formats for non-date items."
   (with-time-stamp-test-env



reply via email to

[Prev in Thread] Current Thread [Next in Thread]