emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] Changes to emacs/lisp/calc/calc-forms.el,v


From: Jay Belanger
Subject: [Emacs-diffs] Changes to emacs/lisp/calc/calc-forms.el,v
Date: Sat, 25 Aug 2007 01:36:37 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Jay Belanger <jpb>      07/08/25 01:36:37

Index: calc-forms.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/calc/calc-forms.el,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- calc-forms.el       26 Jul 2007 05:26:40 -0000      1.29
+++ calc-forms.el       25 Aug 2007 01:36:37 -0000      1.30
@@ -1201,7 +1201,29 @@
     )
   "No doc yet.  See calc manual for now. ")
 
-(defvar var-TimeZone)
+(defvar var-TimeZone nil)
+
+;; From cal-dst
+(defvar calendar-current-time-zone-cache)
+
+(defvar math-calendar-tzinfo 
+  nil
+  "Information about the timezone, retrieved from the calendar.")
+
+(defun math-get-calendar-tzinfo ()
+  "Get information about the timezone from the calendar.
+The result should be a list of two items about the current time zone:
+first, the number of seconds difference from GMT
+second, the number of seconds offset for daylight savings."
+  (if math-calendar-tzinfo
+      math-calendar-tzinfo
+    (require 'cal-dst)
+    (let ((tzinfo (progn
+                    (calendar-current-time-zone)
+                    calendar-current-time-zone-cache)))
+      (setq math-calendar-tzinfo
+            (list (* 60 (abs (nth 0 tzinfo)))
+                  (* 60 (nth 1 tzinfo)))))))
 
 (defun calcFunc-tzone (&optional zone date)
   (if zone
@@ -1233,53 +1255,9 @@
            (t (math-reject-arg zone "*Expected a time zone")))
     (if (calc-var-value 'var-TimeZone)
        (calcFunc-tzone (calc-var-value 'var-TimeZone) date)
-      (let ((p math-tzone-names)
-           (offset 0)
-           (tz '(var error var-error)))
-       (save-excursion
-         (set-buffer (get-buffer-create " *Calc Temporary*"))
-         (erase-buffer)
-         (call-process "date" nil t)
-         (goto-char 1)
-         (let ((case-fold-search t))
-           (while (and p (not (search-forward (car (car p)) nil t)))
-             (setq p (cdr p))))
-         (if (looking-at 
"\\([-+][0-9]?[0-9]\\)\\([0-9][0-9]\\)?\\(\\'\\|[^0-9]\\)")
-             (setq offset (math-add
-                           (string-to-number (buffer-substring
-                                           (match-beginning 1)
-                                           (match-end 1)))
-                           (if (match-beginning 2)
-                               (math-div (string-to-number (buffer-substring
-                                                             (match-beginning 
2)
-                                                             (match-end 2)))
-                                         60)
-                             0)))))
-       (if p
-           (progn
-             (setq p (car p))
-             ;; Try to convert to a generalized time zone.
-             (if (integerp (nth 2 p))
-                 (let ((gen math-tzone-names))
-                   (while (and gen
-                               (not (equal (nth 2 (car gen)) (car p)))
-                               (not (equal (nth 3 (car gen)) (car p)))
-                               (not (equal (nth 4 (car gen)) (car p)))
-                               (not (equal (nth 5 (car gen)) (car p))))
-                     (setq gen (cdr gen)))
-                   (and gen
-                        (setq gen (car gen))
-                        (equal (math-daylight-savings-adjust nil (car gen))
-                               (nth 2 p))
-                        (setq p gen))))
-             (setq tz (math-add (list 'var
-                                      (intern (car p))
-                                      (intern (concat "var-" (car p))))
-                                offset))))
-       (kill-buffer " *Calc Temporary*")
-       (setq var-TimeZone tz)
-       (calc-refresh-evaltos 'var-TimeZone)
-       (calcFunc-tzone tz date)))))
+      (let ((tzinfo (math-get-calendar-tzinfo)))
+        (+ (nth 0 tzinfo) 
+           (* (math-cal-daylight-savings-adjust date) (nth 1 tzinfo)))))))
 
 (defvar math-daylight-savings-hook 'math-std-daylight-savings)
 
@@ -1300,14 +1278,36 @@
     (and math-daylight-savings-hook
         (funcall math-daylight-savings-hook date dt zone bump))))
 
+;;; Based on part of dst-adjust-time in cal-dst.el
+;;; For calcFunc-dst, when zone=nil
+(defun math-cal-daylight-savings-adjust (date)
+  "Return -1 if DATE is using daylight saving, 0 otherwise."
+  (require 'cal-dst)
+  (unless date (setq date (calcFunc-now)))
+  (let* ((dt (math-date-to-dt date))
+         (time (cond
+                ((nth 3 dt)
+                 (nth 3 dt))
+                ((nth 4 dt)
+                 (+ (nth 3 dt) (/ (nth 4 dt) 60.0)))
+                (t
+                 0)))
+         (rounded-abs-date 
+          (+ 
+           (calendar-absolute-from-gregorian 
+            (list (nth 1 dt) (nth 2 dt) (nth 0 dt)))
+           (/ (round (* 60 time)) 60.0 24.0))))
+    (if (dst-in-effect rounded-abs-date)
+        -1
+      0)))
+
 (defun calcFunc-dsadj (date &optional zone)
   (if zone
       (or (eq (car-safe zone) 'var)
          (math-reject-arg zone "*Time zone variable expected"))
-    (setq zone (or (calc-var-value 'var-TimeZone)
+    (setq zone (calc-var-value 'var-TimeZone)))
+  (if zone
                   (progn
-                    (calcFunc-tzone)
-                    (calc-var-value 'var-TimeZone)))))
   (setq zone (and (eq (car-safe zone) 'var)
                  (upcase (symbol-name (nth 1 zone)))))
   (let ((zadj (assoc zone math-tzone-names)))
@@ -1315,6 +1315,23 @@
     (if (integerp (nth 2 zadj))
        (nth 2 zadj)
       (math-daylight-savings-adjust date zone))))
+    (math-cal-daylight-savings-adjust date)))
+
+;; (defun calcFunc-dsadj (date &optional zone)
+;;   (if zone
+;;       (or (eq (car-safe zone) 'var)
+;;       (math-reject-arg zone "*Time zone variable expected"))
+;;     (setq zone (or (calc-var-value 'var-TimeZone)
+;;                (progn
+;;                  (calcFunc-tzone)
+;;                  (calc-var-value 'var-TimeZone)))))
+;;   (setq zone (and (eq (car-safe zone) 'var)
+;;               (upcase (symbol-name (nth 1 zone)))))
+;;   (let ((zadj (assoc zone math-tzone-names)))
+;;     (or zadj (math-reject-arg zone "*Unrecognized time zone name"))
+;;     (if (integerp (nth 2 zadj))
+;;     (nth 2 zadj)
+;;       (math-daylight-savings-adjust date zone))))
 
 (defun calcFunc-tzconv (date z1 z2)
   (if (math-realp date)




reply via email to

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