aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2011-06-30 18:27:40 -0700
committerPaul Eggert2011-06-30 18:27:40 -0700
commitfe955043aa2a44e2bed2bdec963edf0d3ec13fab (patch)
tree18cac822b34d807457730e77cbd8e21489a304c0
parent3103f8b658a3d87f7504471631e8a466bc7ce7c5 (diff)
downloademacs-fe955043aa2a44e2bed2bdec963edf0d3ec13fab.tar.gz
emacs-fe955043aa2a44e2bed2bdec963edf0d3ec13fab.zip
* emacs-lisp/timer.el (timer-relative-time): Use time-add.
-rw-r--r--lisp/ChangeLog2
-rw-r--r--lisp/emacs-lisp/timer.el27
2 files changed, 8 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 336531516ec..3751cea4287 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,7 @@
12011-07-01 Paul Eggert <eggert@cs.ucla.edu> 12011-07-01 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * emacs-lisp/timer.el (timer-relative-time): Use time-add.
4
3 * calendar/timeclock.el (timeclock-seconds-to-time): 5 * calendar/timeclock.el (timeclock-seconds-to-time):
4 Defalias to seconds-to-time, since they're the same thing. 6 Defalias to seconds-to-time, since they're the same thing.
5 7
diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el
index 0a035175041..27fd79a6ad2 100644
--- a/lisp/emacs-lisp/timer.el
+++ b/lisp/emacs-lisp/timer.el
@@ -110,27 +110,12 @@ of SECS seconds since the epoch. SECS may be a fraction."
110(defun timer-relative-time (time secs &optional usecs) 110(defun timer-relative-time (time secs &optional usecs)
111 "Advance TIME by SECS seconds and optionally USECS microseconds. 111 "Advance TIME by SECS seconds and optionally USECS microseconds.
112SECS may be either an integer or a floating point number." 112SECS may be either an integer or a floating point number."
113 ;; FIXME: we should just use (time-add time (list 0 secs usecs)) 113 (let ((delta (if (floatp secs)
114 (let ((high (car time)) 114 (seconds-to-time secs)
115 (low (if (consp (cdr time)) (nth 1 time) (cdr time))) 115 (list (floor secs 65536) (mod secs 65536)))))
116 (micro (if (numberp (car-safe (cdr-safe (cdr time)))) 116 (if usecs
117 (nth 2 time) 117 (setq delta (time-add delta (list 0 0 usecs))))
118 0))) 118 (time-add time delta)))
119 ;; Add
120 (if usecs (setq micro (+ micro usecs)))
121 (if (floatp secs)
122 (setq micro (+ micro (floor (* 1000000 (- secs (floor secs)))))))
123 (setq low (+ low (floor secs)))
124
125 ;; Normalize
126 ;; `/' rounds towards zero while `mod' returns a positive number,
127 ;; so we can't rely on (= a (+ (* 100 (/ a 100)) (mod a 100))).
128 (setq low (+ low (/ micro 1000000) (if (< micro 0) -1 0)))
129 (setq micro (mod micro 1000000))
130 (setq high (+ high (/ low 65536) (if (< low 0) -1 0)))
131 (setq low (logand low 65535))
132
133 (list high low (and (/= micro 0) micro))))
134 119
135(defun timer--time-less-p (t1 t2) 120(defun timer--time-less-p (t1 t2)
136 "Say whether time value T1 is less than time value T2." 121 "Say whether time value T1 is less than time value T2."