Kaynağa Gözat

Avoid using time-to-seconds

Carsten Dominik 15 yıl önce
ebeveyn
işleme
1152565013
6 değiştirilmiş dosya ile 59 ekleme ve 37 silme
  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>
 
+	* 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
 	function.
 

+ 3 - 3
lisp/org-agenda.el

@@ -2618,7 +2618,7 @@ continue from there."
 
 (defvar org-agenda-markers nil
   "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.")
 
 (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
 no longer in use."
   (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)
     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
 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."
-  (when (> (- (time-to-seconds (current-time))
+  (when (> (- (org-float-time)
 	      org-agenda-last-marker-time)
 	   5)
     (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
 previous clocking intervals."
   (let ((currently-clocked-time
-	 (floor (- (time-to-seconds (current-time))
-		   (time-to-seconds org-clock-start-time)) 60)))
+	 (floor (- (org-float-time)
+		   (org-float-time org-clock-start-time)) 60)))
     (+ currently-clocked-time (or org-clock-total-time 0))))
 
 (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))
 	  (insert "--")
 	  (setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
-	  (setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
-		     (time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
+	  (setq s (- (org-float-time (apply 'encode-time (org-parse-time-string te)))
+		     (org-float-time (apply 'encode-time (org-parse-time-string ts))))
 		h (floor (/ s 3600))
 		s (- s (* 3600 h))
 		m (floor (/ s 60))
@@ -868,8 +868,8 @@ TSTART and TEND can mark a time range to be considered."
 	 time)
     (if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart)))
     (if (stringp tend) (setq tend (org-time-string-to-seconds tend)))
-    (if (consp tstart) (setq tstart (time-to-seconds tstart)))
-    (if (consp tend) (setq tend (time-to-seconds tend)))
+    (if (consp tstart) (setq tstart (org-float-time tstart)))
+    (if (consp tend) (setq tend (org-float-time tend)))
     (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
     (save-excursion
       (goto-char (point-max))
@@ -879,9 +879,9 @@ TSTART and TEND can mark a time range to be considered."
 	  ;; Two time stamps
 	  (setq ts (match-string 2)
 		te (match-string 3)
-		ts (time-to-seconds
+		ts (org-float-time
 		    (apply 'encode-time (org-parse-time-string ts)))
-		te (time-to-seconds
+		te (org-float-time
 		    (apply 'encode-time (org-parse-time-string te)))
 		ts (if tstart (max ts tstart) ts)
 		te (if tend (min te tend) te)
@@ -1222,9 +1222,9 @@ the currently selected interval size."
       (when (and te (listp te))
 	(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
       ;; 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)))))
-      (if te (setq te (time-to-seconds
+      (if te (setq te (org-float-time
 		       (apply 'encode-time (org-parse-time-string te)))))
       (move-marker ins (point))
       (setq ipos (point))
@@ -1402,9 +1402,9 @@ the currently selected interval size."
     (when block
       (setq cc (org-clock-special-range block nil t)
 	    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)))))
-    (if te (setq te (time-to-seconds
+    (if te (setq te (org-float-time
 		     (apply 'encode-time (org-parse-time-string te)))))
     (setq p1 (plist-put p1 :header ""))
     (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
 	   (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)
 
 ;; 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 org-timer-start-time
 	      (seconds-to-time
-	       (-
-		(time-to-seconds (current-time))
-		(org-timer-hms-to-secs s)))))
+	       (- (org-float-time) (org-timer-hms-to-secs s)))))
       (org-timer-set-mode-line 'on)
       (message "Timer start time set to %s, current value is %s"
 	       (format-time-string "%T" org-timer-start-time)
@@ -97,9 +95,9 @@ the region 0:00:00."
     (setq org-timer-start-time
 	  (seconds-to-time
 	   (-
-	    (time-to-seconds (current-time))
-	    (- (time-to-seconds org-timer-pause-time)
-	       (time-to-seconds org-timer-start-time))))
+	    (org-float-time)
+	    (- (org-float-time org-timer-pause-time)
+	       (org-float-time org-timer-start-time))))
 	  org-timer-pause-time nil)
     (org-timer-set-mode-line 'on)
     (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)))))
 
 (defun org-timer-seconds ()
-  (- (time-to-seconds (or org-timer-pause-time (current-time)))
-     (time-to-seconds org-timer-start-time)))
+  (- (org-float-time (or org-timer-pause-time (current-time)))
+     (org-float-time org-timer-start-time)))
 
 ;;;###autoload
 (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)
 	  (setq ts (match-string 1)
 		te (match-string 3))
-	  (setq s (- (time-to-seconds
+	  (setq s (- (org-float-time
 		      (apply 'encode-time (org-parse-time-string te)))
-		     (time-to-seconds
+		     (org-float-time
 		      (apply 'encode-time (org-parse-time-string ts))))
 		neg (< s 0)
 		s (abs s)
@@ -6657,7 +6657,7 @@ WITH-CASE, the sorting considers case as well."
 			   (re-search-forward org-ts-regexp-both
 					      (point-at-eol) t))
 		       (org-time-string-to-seconds (match-string 0))
-		     (time-to-seconds now)))
+		     (org-float-time now)))
 		  ((= dcst ?f)
 		   (if getkey-func
 		       (progn
@@ -6681,24 +6681,24 @@ WITH-CASE, the sorting considers case as well."
 		 (if (or (re-search-forward org-ts-regexp end t)
 			 (re-search-forward org-ts-regexp-both end t))
 		     (org-time-string-to-seconds (match-string 0))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?c)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward
 		      (concat "^[ \t]*\\[" org-ts-regexp1 "\\]")
 		      end t)
 		     (org-time-string-to-seconds (match-string 0))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?s)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward org-scheduled-time-regexp end t)
 		     (org-time-string-to-seconds (match-string 1))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?d)
 	       (let ((end (save-excursion (outline-next-heading) (point))))
 		 (if (re-search-forward org-deadline-time-regexp end t)
 		     (org-time-string-to-seconds (match-string 1))
-		   (time-to-seconds now))))
+		   (org-float-time now))))
 	      ((= dcst ?p)
 	       (if (re-search-forward org-priority-regexp (point-at-eol) t)
 		   (string-to-char (match-string 2))
@@ -6757,7 +6757,7 @@ If WITH-CASE is non-nil, the sorting will be case-sensitive."
 	    (lambda (x)
 	      (if (or (string-match org-ts-regexp x)
 		      (string-match org-ts-regexp-both x))
-		  (time-to-seconds
+		  (org-float-time
 		   (org-time-string-to-time (match-string 0 x)))
 		0))
 	    comparefun (if (= dcst sorting-type) '< '>)))
@@ -13030,8 +13030,8 @@ days in order to avoid rounding problems."
 	  (match-end (match-end 0))
 	  (time1 (org-time-string-to-time ts1))
 	  (time2 (org-time-string-to-time ts2))
-	  (t1 (time-to-seconds time1))
-	  (t2 (time-to-seconds time2))
+	  (t1 (org-float-time time1))
+	  (t2 (org-float-time time2))
 	  (diff (abs (- t2 t1)))
 	  (negative (< (- t2 t1) 0))
 	  ;; (ys (floor (* 365 24 60 60)))
@@ -13087,7 +13087,7 @@ days in order to avoid rounding problems."
 (defun org-time-string-to-time (s)
   (apply 'encode-time (org-parse-time-string 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)
   "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."
   (interactive)
   ;; 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: ")))
-         (time2 (time-to-seconds
+         (time2 (org-float-time
                  (org-read-date nil 'to-time nil "End date:")))
          ;; callback function
          (callback (lambda ()
                      (let ((time
-                            (time-to-seconds
+                            (org-float-time
                              (apply 'encode-time
                                     (org-parse-time-string
                                      (match-string 1))))))