changeset 2920:c47652dc3400

Some time-handling patches from Paul Eggert: * calendar.el (calendar-current-time-zone): New function. (calendar-time-zone, calendar-standard-time-zone-name, calendar-daylight-time-zone-name): Use it instead of current-time-zone. * sendmail.el (mail-do-fcc): Use the same absolute time for both current-time-string and current-time-zone. Adjust to new format returned by current-time-zone.
author Jim Blandy <jimb@redhat.com>
date Thu, 20 May 1993 06:28:46 +0000
parents 2420d37c5335
children 37503f466755
files lisp/calendar/calendar.el lisp/mail/sendmail.el
diffstat 2 files changed, 56 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calendar/calendar.el	Thu May 20 06:18:08 1993 +0000
+++ b/lisp/calendar/calendar.el	Thu May 20 06:28:46 1993 +0000
@@ -479,6 +479,55 @@
 `calendar-longitude', calendar-latitude'.  Default value is just the latitude,
 longitude pair.")
 
+(defun calendar-current-time-zone ()
+  "Return the offset, savings state, and names for the current time zone.
+This returns a list of the form (OFFSET SAVINGS-FLAG STANDARD SAVINGS).
+This list is calculated from a heuristic that is usually correct;
+to get more reliable results, use current-time-zone.
+OFFSET is an integer specifying how many minutes east of Greenwich the
+    current time zone is located.  A negative value means west of
+    Greenwich.  This describes the standard time; if daylight
+    savings time is in effect, it does not affect this value.
+SAVINGS-FLAG is non-nil iff daylight savings time or some other sort
+    of seasonal time adjustment is in effect.
+STANDARD is a string giving the name of the time zone when no seasonal
+    time adjustment is in effect.
+SAVINGS is a string giving the name of the time zone when there is a
+    seasonal time adjustment in effect.
+If the local area does not use a seasonal time adjustment,
+SAVINGS-FLAG is always nil, and STANDARD and SAVINGS are equal.
+
+Some operating systems cannot provide all this information to Emacs;
+in this case, calendar-current-time-zone returns a list containing nil for
+the data it can't find."
+  (let* ((quarter-year-seconds 7889238.0) ; # number of seconds in 1/4 year
+	 (current-time-arithmetic-base 65536.0)
+	 (now (current-time))
+	 (now-zone (current-time-zone now))
+	 (now-offset (car now-zone))
+	 (now-name (car (cdr now-zone)))
+	 probe-zone
+	 (probe-offset now-offset)
+	 (i 0))
+    ;; Heuristic: probe the time zone offset in the next three calendar
+    ;; quarters, looking for a time zone offset different from now.
+    (while (and (< i 4) (eq now-offset probe-offset))
+      (let ((probe
+	     (list (+ (car now) (round (/ (* i quarter-year-seconds)
+					  current-time-arithmetic-base)))
+		   0 0)))
+        (setq probe-zone (current-time-zone probe))
+	(setq probe-offset (car probe-zone))
+	(setq i (1+ i))))
+    (if (or (eq now-offset probe-offset) (not now-offset) (not probe-offset))
+	(list (and now-offset (/ now-offset 60)) nil now-name now-name)
+      (let ((std-offset (min now-offset probe-offset))
+	    (probe-name (car (cdr probe-zone))))
+	(list (/ std-offset 60)
+	      t
+	      (if (eq std-offset now-offset) now-name probe-name)
+	      (if (eq std-offset now-offset) probe-name now-name))))))
+
 ;;; Since the following three defvars are marked to go into
 ;;; loaddefs.el, they will be evaluated when Emacs is dumped.
 ;;; However, these variables' appropriate values really depend on the
@@ -497,7 +546,7 @@
 package loads.")
 ;;; If the user has given this a real value, don't wipe it out.
 (or calendar-time-zone
-    (setq calendar-time-zone (car (current-time-zone))))
+    (setq calendar-time-zone (car (calendar-current-time-zone))))
 
 ;;;###autoload
 (defvar calendar-standard-time-zone-name nil
@@ -509,7 +558,7 @@
 ;;; If the user has given this a value, don't wipe it out.
 (or calendar-standard-time-zone-name
     (setq calendar-standard-time-zone-name
-          (car (nthcdr 2 (current-time-zone)))))
+          (car (nthcdr 2 (calendar-current-time-zone)))))
 
 ;;;###autoload
 (defvar calendar-daylight-time-zone-name nil
@@ -521,7 +570,7 @@
 ;;; If the user has given this a value, don't wipe it out.
 (or calendar-daylight-time-zone-name
     (setq calendar-daylight-time-zone-name
-          (car (nthcdr 3 (current-time-zone)))))
+          (car (nthcdr 3 (calendar-current-time-zone)))))
   
 ;;;###autoload
 (defvar calendar-daylight-savings-starts
--- a/lisp/mail/sendmail.el	Thu May 20 06:18:08 1993 +0000
+++ b/lisp/mail/sendmail.el	Thu May 20 06:28:46 1993 +0000
@@ -355,6 +355,7 @@
 (defun mail-do-fcc (header-end)
   (let (fcc-list
 	(rmailbuf (current-buffer))
+	(time (current-time))
 	timezone
 	(tembuf (generate-new-buffer " rmail output"))
 	(case-fold-search t))
@@ -369,8 +370,8 @@
 			     fcc-list))
 	(delete-region (match-beginning 0)
 		       (progn (forward-line 1) (point))))
-      (let* ((foo (current-time-zone))
-	     (offset (+ (car foo) (if (nth 1 foo) 60 0)))
+      (let* ((foo (current-time-zone time))
+	     (offset (if (car foo) (/ (car foo) 60) 0))
 	     (abs (abs offset)))
 	(setq timezone (format "%s%02d%02d"
 			       (if (< offset 0) "-" "+")
@@ -379,7 +380,7 @@
       (set-buffer tembuf)
       (erase-buffer)
       (insert "From " (user-login-name) " "
-	      (current-time-string) "\n")
+	      (current-time-string time) "\n")
       ;; Insert the time zone before the year.
       (forward-char -1)
       (forward-word -1)