Browse Source

Avoid using time-to-seconds

Carsten Dominik 15 years ago
parent
commit
1152565013
6 changed files with 59 additions and 37 deletions
  1. 17 0
      lisp/ChangeLog
  2. 3 3
      lisp/org-agenda.el
  3. 12 12
      lisp/org-clock.el
  4. 7 0
      lisp/org-compat.el
  5. 6 8
      lisp/org-timer.el
  6. 14 14
      lisp/org.el

+ 17 - 0
lisp/ChangeLog

@@ -1,5 +1,22 @@
 2009-09-02  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-09-02  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-compat.el (org-float-time): New function.
+
+	* org.el (org-clock-update-time-maybe)
+	(org-sort-entries-or-items, org-do-sort)
+	(org-evaluate-time-range, org-time-string-to-seconds)
+	(org-closed-in-range): Use `org-float-time'.
+
+	* org-timer.el (org-timer-start, org-timer-pause-or-continue)
+	(org-timer-seconds):  Use `org-float-time'.
+
+	* org-clock.el (org-clock-get-clocked-time, org-clock-out)
+	(org-clock-sum, org-dblock-write:clocktable)
+	(org-clocktable-steps):  Use `org-float-time'.
+
+	* org-agenda.el (org-agenda-last-marker-time)
+	(org-agenda-new-marker, org-diary):  Use `org-float-time'.
+
 	* org-compat.el (w32-focus-frame): Declare the w32-focus-frame
 	* org-compat.el (w32-focus-frame): Declare the w32-focus-frame
 	function.
 	function.
 
 

+ 3 - 3
lisp/org-agenda.el

@@ -2618,7 +2618,7 @@ continue from there."
 
 
 (defvar org-agenda-markers nil
 (defvar org-agenda-markers nil
   "List of all currently active markers created by `org-agenda'.")
   "List of all currently active markers created by `org-agenda'.")
-(defvar org-agenda-last-marker-time (time-to-seconds (current-time))
+(defvar org-agenda-last-marker-time (org-float-time)
   "Creation time of the last agenda marker.")
   "Creation time of the last agenda marker.")
 
 
 (defun org-agenda-new-marker (&optional pos)
 (defun org-agenda-new-marker (&optional pos)
@@ -2626,7 +2626,7 @@ continue from there."
 Org-mode keeps a list of these markers and resets them when they are
 Org-mode keeps a list of these markers and resets them when they are
 no longer in use."
 no longer in use."
   (let ((m (copy-marker (or pos (point)))))
   (let ((m (copy-marker (or pos (point)))))
-    (setq org-agenda-last-marker-time (time-to-seconds (current-time)))
+    (setq org-agenda-last-marker-time (org-float-time))
     (push m org-agenda-markers)
     (push m org-agenda-markers)
     m))
     m))
 
 
@@ -3672,7 +3672,7 @@ So the example above may also be written as
 The function expects the lisp variables `entry' and `date' to be provided
 The function expects the lisp variables `entry' and `date' to be provided
 by the caller, because this is how the calendar works.  Don't use this
 by the caller, because this is how the calendar works.  Don't use this
 function from a program - use `org-agenda-get-day-entries' instead."
 function from a program - use `org-agenda-get-day-entries' instead."
-  (when (> (- (time-to-seconds (current-time))
+  (when (> (- (org-float-time)
 	      org-agenda-last-marker-time)
 	      org-agenda-last-marker-time)
 	   5)
 	   5)
     (org-agenda-reset-markers))
     (org-agenda-reset-markers))

+ 12 - 12
lisp/org-clock.el

@@ -390,8 +390,8 @@ If not, show simply the clocked time like 01:50."
 The time returned includes the the time spent on this task in
 The time returned includes the the time spent on this task in
 previous clocking intervals."
 previous clocking intervals."
   (let ((currently-clocked-time
   (let ((currently-clocked-time
-	 (floor (- (time-to-seconds (current-time))
+	 (floor (- (org-float-time)
-		   (time-to-seconds org-clock-start-time)) 60)))
+		   (org-float-time org-clock-start-time)) 60)))
     (+ currently-clocked-time (or org-clock-total-time 0))))
     (+ currently-clocked-time (or org-clock-total-time 0))))
 
 
 (defun org-clock-modify-effort-estimate (&optional value)
 (defun org-clock-modify-effort-estimate (&optional value)
@@ -760,8 +760,8 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
 	  (delete-region (point) (point-at-eol))
 	  (delete-region (point) (point-at-eol))
 	  (insert "--")
 	  (insert "--")
 	  (setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
 	  (setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
-	  (setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
+	  (setq s (- (org-float-time (apply 'encode-time (org-parse-time-string te)))
-		     (time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
+		     (org-float-time (apply 'encode-time (org-parse-time-string ts))))
 		h (floor (/ s 3600))
 		h (floor (/ s 3600))
 		s (- s (* 3600 h))
 		s (- s (* 3600 h))
 		m (floor (/ s 60))
 		m (floor (/ s 60))
@@ -868,8 +868,8 @@ TSTART and TEND can mark a time range to be considered."
 	 time)
 	 time)
     (if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart)))
     (if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart)))
     (if (stringp tend) (setq tend (org-time-string-to-seconds tend)))
     (if (stringp tend) (setq tend (org-time-string-to-seconds tend)))
-    (if (consp tstart) (setq tstart (time-to-seconds tstart)))
+    (if (consp tstart) (setq tstart (org-float-time tstart)))
-    (if (consp tend) (setq tend (time-to-seconds tend)))
+    (if (consp tend) (setq tend (org-float-time tend)))
     (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
     (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
     (save-excursion
     (save-excursion
       (goto-char (point-max))
       (goto-char (point-max))
@@ -879,9 +879,9 @@ TSTART and TEND can mark a time range to be considered."
 	  ;; Two time stamps
 	  ;; Two time stamps
 	  (setq ts (match-string 2)
 	  (setq ts (match-string 2)
 		te (match-string 3)
 		te (match-string 3)
-		ts (time-to-seconds
+		ts (org-float-time
 		    (apply 'encode-time (org-parse-time-string ts)))
 		    (apply 'encode-time (org-parse-time-string ts)))
-		te (time-to-seconds
+		te (org-float-time
 		    (apply 'encode-time (org-parse-time-string te)))
 		    (apply 'encode-time (org-parse-time-string te)))
 		ts (if tstart (max ts tstart) ts)
 		ts (if tstart (max ts tstart) ts)
 		te (if tend (min te tend) te)
 		te (if tend (min te tend) te)
@@ -1222,9 +1222,9 @@ the currently selected interval size."
       (when (and te (listp te))
       (when (and te (listp te))
 	(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
 	(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
       ;; Now the times are strings we can parse.
       ;; Now the times are strings we can parse.
-      (if ts (setq ts (time-to-seconds
+      (if ts (setq ts (org-float-time
 		       (apply 'encode-time (org-parse-time-string ts)))))
 		       (apply 'encode-time (org-parse-time-string ts)))))
-      (if te (setq te (time-to-seconds
+      (if te (setq te (org-float-time
 		       (apply 'encode-time (org-parse-time-string te)))))
 		       (apply 'encode-time (org-parse-time-string te)))))
       (move-marker ins (point))
       (move-marker ins (point))
       (setq ipos (point))
       (setq ipos (point))
@@ -1402,9 +1402,9 @@ the currently selected interval size."
     (when block
     (when block
       (setq cc (org-clock-special-range block nil t)
       (setq cc (org-clock-special-range block nil t)
 	    ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
 	    ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
-    (if ts (setq ts (time-to-seconds
+    (if ts (setq ts (org-float-time
 		     (apply 'encode-time (org-parse-time-string ts)))))
 		     (apply 'encode-time (org-parse-time-string ts)))))
-    (if te (setq te (time-to-seconds
+    (if te (setq te (org-float-time
 		     (apply 'encode-time (org-parse-time-string te)))))
 		     (apply 'encode-time (org-parse-time-string te)))))
     (setq p1 (plist-put p1 :header ""))
     (setq p1 (plist-put p1 :header ""))
     (setq p1 (plist-put p1 :step nil))
     (setq p1 (plist-put p1 :step nil))

+ 7 - 0
lisp/org-compat.el

@@ -355,6 +355,13 @@ that can be added."
 	 (when focus-follows-mouse
 	 (when focus-follows-mouse
 	   (set-mouse-position frame (1- (frame-width frame)) 0)))))
 	   (set-mouse-position frame (1- (frame-width frame)) 0)))))
 
 
+(defun org-float-time (&optional time)
+  "Convert time value TIME to a floating point number.
+TIME defaults to the current time."
+  (if (featurep 'xemacs)
+      (time-to-seconds (or time (current-time)))
+    (float-time time)))
+
 (provide 'org-compat)
 (provide 'org-compat)
 
 
 ;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe
 ;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe

+ 6 - 8
lisp/org-timer.el

@@ -78,9 +78,7 @@ the region 0:00:00."
 	  (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
 	  (setq delta (org-timer-hms-to-secs (org-timer-fix-incomplete s)))))
 	(setq org-timer-start-time
 	(setq org-timer-start-time
 	      (seconds-to-time
 	      (seconds-to-time
-	       (-
+	       (- (org-float-time) (org-timer-hms-to-secs s)))))
-		(time-to-seconds (current-time))
-		(org-timer-hms-to-secs s)))))
       (org-timer-set-mode-line 'on)
       (org-timer-set-mode-line 'on)
       (message "Timer start time set to %s, current value is %s"
       (message "Timer start time set to %s, current value is %s"
 	       (format-time-string "%T" org-timer-start-time)
 	       (format-time-string "%T" org-timer-start-time)
@@ -97,9 +95,9 @@ the region 0:00:00."
     (setq org-timer-start-time
     (setq org-timer-start-time
 	  (seconds-to-time
 	  (seconds-to-time
 	   (-
 	   (-
-	    (time-to-seconds (current-time))
+	    (org-float-time)
-	    (- (time-to-seconds org-timer-pause-time)
+	    (- (org-float-time org-timer-pause-time)
-	       (time-to-seconds org-timer-start-time))))
+	       (org-float-time org-timer-start-time))))
 	  org-timer-pause-time nil)
 	  org-timer-pause-time nil)
     (org-timer-set-mode-line 'on)
     (org-timer-set-mode-line 'on)
     (message "Timer continues at %s" (org-timer-value-string)))
     (message "Timer continues at %s" (org-timer-value-string)))
@@ -133,8 +131,8 @@ that was not started at the correct moment."
   (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds)))))
   (format org-timer-format (org-timer-secs-to-hms (floor (org-timer-seconds)))))
 
 
 (defun org-timer-seconds ()
 (defun org-timer-seconds ()
-  (- (time-to-seconds (or org-timer-pause-time (current-time)))
+  (- (org-float-time (or org-timer-pause-time (current-time)))
-     (time-to-seconds org-timer-start-time)))
+     (org-float-time org-timer-start-time)))
 
 
 ;;;###autoload
 ;;;###autoload
 (defun org-timer-change-times-in-region (beg end delta)
 (defun org-timer-change-times-in-region (beg end delta)

+ 14 - 14
lisp/org.el

@@ -3165,9 +3165,9 @@ Otherwise, return nil."
 	  (end-of-line 1)
 	  (end-of-line 1)
 	  (setq ts (match-string 1)
 	  (setq ts (match-string 1)
 		te (match-string 3))
 		te (match-string 3))
-	  (setq s (- (time-to-seconds
+	  (setq s (- (org-float-time
 		      (apply 'encode-time (org-parse-time-string te)))
 		      (apply 'encode-time (org-parse-time-string te)))
-		     (time-to-seconds
+		     (org-float-time
 		      (apply 'encode-time (org-parse-time-string ts))))
 		      (apply 'encode-time (org-parse-time-string ts))))
 		neg (< s 0)
 		neg (< s 0)
 		s (abs s)
 		s (abs s)
@@ -6657,7 +6657,7 @@ WITH-CASE, the sorting considers case as well."
 			   (re-search-forward org-ts-regexp-both
 			   (re-search-forward org-ts-regexp-both
 					      (point-at-eol) t))
 					      (point-at-eol) t))
 		       (org-time-string-to-seconds (match-string 0))
 		       (org-time-string-to-seconds (match-string 0))
-		     (time-to-seconds now)))
+		     (org-float-time now)))
 		  ((= dcst ?f)
 		  ((= dcst ?f)
 		   (if getkey-func
 		   (if getkey-func
 		       (progn
 		       (progn
@@ -6681,24 +6681,24 @@ WITH-CASE, the sorting considers case as well."
 		 (if (or (re-search-forward org-ts-regexp end t)
 		 (if (or (re-search-forward org-ts-regexp end t)
 			 (re-search-forward org-ts-regexp-both end t))
 			 (re-search-forward org-ts-regexp-both end t))
 		     (org-time-string-to-seconds (match-string 0))
 		     (org-time-string-to-seconds (match-string 0))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?c)
 	      ((= dcst ?c)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward
 		 (if (re-search-forward
 		      (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
 		      (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
 		      end t)
 		      end t)
 		     (org-time-string-to-seconds (match-string 0))
 		     (org-time-string-to-seconds (match-string 0))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?s)
 	      ((= dcst ?s)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward org-scheduled-time-regexp end t)
 		 (if (re-search-forward org-scheduled-time-regexp end t)
 		     (org-time-string-to-seconds (match-string 1))
 		     (org-time-string-to-seconds (match-string 1))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?d)
 	      ((= dcst ?d)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward org-deadline-time-regexp end t)
 		 (if (re-search-forward org-deadline-time-regexp end t)
 		     (org-time-string-to-seconds (match-string 1))
 		     (org-time-string-to-seconds (match-string 1))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?p)
 	      ((= dcst ?p)
 	       (if (re-search-forward org-priority-regexp (point-at-eol) t)
 	       (if (re-search-forward org-priority-regexp (point-at-eol) t)
 		   (string-to-char (match-string 2))
 		   (string-to-char (match-string 2))
@@ -6757,7 +6757,7 @@ If WITH-CASE is non-nil, the sorting will be case-sensitive."
 	    (lambda (x)
 	    (lambda (x)
 	      (if (or (string-match org-ts-regexp x)
 	      (if (or (string-match org-ts-regexp x)
 		      (string-match org-ts-regexp-both x))
 		      (string-match org-ts-regexp-both x))
-		  (time-to-seconds
+		  (org-float-time
 		   (org-time-string-to-time (match-string 0 x)))
 		   (org-time-string-to-time (match-string 0 x)))
 		0))
 		0))
 	    comparefun (if (= dcst sorting-type) '< '>)))
 	    comparefun (if (= dcst sorting-type) '< '>)))
@@ -13030,8 +13030,8 @@ days in order to avoid rounding problems."
 	  (match-end (match-end 0))
 	  (match-end (match-end 0))
 	  (time1 (org-time-string-to-time ts1))
 	  (time1 (org-time-string-to-time ts1))
 	  (time2 (org-time-string-to-time ts2))
 	  (time2 (org-time-string-to-time ts2))
-	  (t1 (time-to-seconds time1))
+	  (t1 (org-float-time time1))
-	  (t2 (time-to-seconds time2))
+	  (t2 (org-float-time time2))
 	  (diff (abs (- t2 t1)))
 	  (diff (abs (- t2 t1)))
 	  (negative (< (- t2 t1) 0))
 	  (negative (< (- t2 t1) 0))
 	  ;; (ys (floor (* 365 24 60 60)))
 	  ;; (ys (floor (* 365 24 60 60)))
@@ -13087,7 +13087,7 @@ days in order to avoid rounding problems."
 (defun org-time-string-to-time (s)
 (defun org-time-string-to-time (s)
   (apply 'encode-time (org-parse-time-string s)))
   (apply 'encode-time (org-parse-time-string s)))
 (defun org-time-string-to-seconds (s)
 (defun org-time-string-to-seconds (s)
-  (time-to-seconds (org-time-string-to-time s)))
+  (org-float-time (org-time-string-to-time s)))
 
 
 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
 (defun org-time-string-to-absolute (s &optional daynr prefer show-all)
   "Convert a time stamp to an absolute day number.
   "Convert a time stamp to an absolute day number.
@@ -17137,14 +17137,14 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
 Still experimental, may disappear in the future."
 Still experimental, may disappear in the future."
   (interactive)
   (interactive)
   ;; Get the time interval from the user.
   ;; Get the time interval from the user.
-  (let* ((time1 (time-to-seconds
+  (let* ((time1 (org-float-time
                  (org-read-date nil 'to-time nil "Starting date: ")))
                  (org-read-date nil 'to-time nil "Starting date: ")))
-         (time2 (time-to-seconds
+         (time2 (org-float-time
                  (org-read-date nil 'to-time nil "End date:")))
                  (org-read-date nil 'to-time nil "End date:")))
          ;; callback function
          ;; callback function
          (callback (lambda ()
          (callback (lambda ()
                      (let ((time
                      (let ((time
-                            (time-to-seconds
+                            (org-float-time
                              (apply 'encode-time
                              (apply 'encode-time
                                     (org-parse-time-string
                                     (org-parse-time-string
                                      (match-string 1))))))
                                      (match-string 1))))))