emacs-diffs
[Top][All Lists]
Advanced

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

master 15f20c0 09/13: Simplify RFC 5322 time zone generation


From: Paul Eggert
Subject: master 15f20c0 09/13: Simplify RFC 5322 time zone generation
Date: Mon, 6 Dec 2021 02:24:23 -0500 (EST)

branch: master
commit 15f20c0bd06a25bbb4ea90e501ef85290509c43b
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Simplify RFC 5322 time zone generation
    
    * lisp/mail/feedmail.el (feedmail-rfc822-time-zone)
    (feedmail-rfc822-date, feedmail-default-message-id-generator):
    * lisp/mail/mail-utils.el (mail-rfc822-time-zone, mail-rfc822-date):
    * lisp/timezone.el (timezone-make-arpa-date):
    Simplify by using format-time-string with %z.
    
    * lisp/mail/feedmail.el (feedmail-rfc822-time-zone):
    * lisp/mail/mail-utils.el (mail-rfc822-time-zone):
    Mark these should-have-been-internal functions obsolete.
---
 lisp/mail/feedmail.el   | 18 ++++++------------
 lisp/mail/mail-utils.el | 15 ++++-----------
 lisp/timezone.el        |  5 +----
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/lisp/mail/feedmail.el b/lisp/mail/feedmail.el
index fe686cb..32edc29 100644
--- a/lisp/mail/feedmail.el
+++ b/lisp/mail/feedmail.el
@@ -2336,19 +2336,14 @@ mapped to mostly alphanumerics for safety."
 
 ;; from a similar function in mail-utils.el
 (defun feedmail-rfc822-time-zone (time)
+  (declare (obsolete format-time-string "29.1"))
   (feedmail-say-debug ">in-> feedmail-rfc822-time-zone %s" time)
-  (let* ((sec (or (car (current-time-zone time)) 0))
-        (absmin (/ (abs sec) 60)))
-    (format "%c%02d%02d" (if (< sec 0) ?- ?+) (/ absmin 60) (% absmin 60))))
+  (format-time-string "%z" time))
 
 (defun feedmail-rfc822-date (arg-time)
   (feedmail-say-debug ">in-> feedmail-rfc822-date %s" arg-time)
-  (let ((time (or arg-time (current-time)))
-       (system-time-locale "C"))
-    (concat
-     (format-time-string "%a, %e %b %Y %T " time)
-     (feedmail-rfc822-time-zone time)
-     )))
+  (let ((system-time-locale "C"))
+    (format-time-string "%a, %e %b %Y %T %z" arg-time)))
 
 (defun feedmail-send-it-immediately-wrapper ()
   "Wrapper to catch skip-me-i."
@@ -2847,10 +2842,9 @@ probably not appropriate for you."
     (if (and (not feedmail-queue-use-send-time-for-message-id) maybe-file)
        (setq date-time (file-attribute-modification-time
                         (file-attributes maybe-file))))
-    (format "<%d-%s%s%s>"
+    (format "<%d-%s%s>"
            (mod (random) 10000)
-           (format-time-string "%a%d%b%Y%H%M%S" date-time)
-           (feedmail-rfc822-time-zone date-time)
+           (format-time-string "%a%d%b%Y%H%M%S%z" date-time)
            end-stuff))
   )
 
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el
index 3eb3ccb..f1b0590 100644
--- a/lisp/mail/mail-utils.el
+++ b/lisp/mail/mail-utils.el
@@ -368,19 +368,12 @@ matches may be returned from the message body."
   labels)
 
 (defun mail-rfc822-time-zone (time)
-  (let* ((sec (or (car (current-time-zone time)) 0))
-        (absmin (/ (abs sec) 60)))
-    (format "%c%02d%02d" (if (< sec 0) ?- ?+) (/ absmin 60) (% absmin 60))))
+  (declare (obsolete format-time-string "29.1"))
+  (format-time-string "%z" time))
 
 (defun mail-rfc822-date ()
-  (let* ((time (current-time))
-        (s (current-time-string time)))
-    (string-match "[^ ]+ +\\([^ ]+\\) +\\([^ ]+\\) \\([^ ]+\\) \\([^ ]+\\)" s)
-    (concat (substring s (match-beginning 2) (match-end 2)) " "
-           (substring s (match-beginning 1) (match-end 1)) " "
-           (substring s (match-beginning 4) (match-end 4)) " "
-           (substring s (match-beginning 3) (match-end 3)) " "
-           (mail-rfc822-time-zone time))))
+  (let ((system-time-locale "C"))
+    (format-time-string "%-d %b %Y %T %z")))
 
 (defun mail-mbox-from ()
   "Return an mbox \"From \" line for the current message.
diff --git a/lisp/timezone.el b/lisp/timezone.el
index 2c96343..0fcdbdb 100644
--- a/lisp/timezone.el
+++ b/lisp/timezone.el
@@ -95,10 +95,7 @@ if nil, the local time zone is assumed."
 Optional argument TIMEZONE specifies a time zone."
   (let ((zone
         (if (listp timezone)
-            (let* ((m (timezone-zone-to-minute timezone))
-                   (absm (if (< m 0) (- m) m)))
-              (format "%c%02d%02d"
-                      (if (< m 0) ?- ?+) (/ absm 60) (% absm 60)))
+            (format-time-string "%z" 0 (or timezone 0))
           timezone)))
     (format "%02d %s %04d %s %s"
            day



reply via email to

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