瀏覽代碼

Fix bug with `org-clock-rounding-minutes'

* org-clock.el (org-clock-in, org-clock-in-last): Tell
`org-current-time' to always return a past time.

* org.el (org-current-time): New argument `past' to force
returning a past time when rounding.

If (setq org-clock-rounding-minutes 5) and time is 12:33
the clock start time would be 12:35, and the clock mode-line
would display 0:-2.  The fix ensures the rounded value is
always in the past.
Bastien Guerry 12 年之前
父節點
當前提交
d1e57bd884
共有 2 個文件被更改,包括 17 次插入12 次删除
  1. 4 4
      lisp/org-clock.el
  2. 13 8
      lisp/org.el

+ 4 - 4
lisp/org-clock.el

@@ -1271,11 +1271,11 @@ make this the default behavior.)"
 			      (format
 			      (format
 			       "You stopped another clock %d mins ago; start this one from then? "
 			       "You stopped another clock %d mins ago; start this one from then? "
 			       (/ (- (org-float-time
 			       (/ (- (org-float-time
-				      (org-current-time org-clock-rounding-minutes))
+				      (org-current-time org-clock-rounding-minutes t))
 				     (org-float-time leftover)) 60)))
 				     (org-float-time leftover)) 60)))
 			     leftover)
 			     leftover)
 			start-time
 			start-time
-			(org-current-time org-clock-rounding-minutes)))
+			(org-current-time org-clock-rounding-minutes t)))
 	      (setq ts (org-insert-time-stamp org-clock-start-time
 	      (setq ts (org-insert-time-stamp org-clock-start-time
 					      'with-hm 'inactive))))
 					      'with-hm 'inactive))))
 	    (move-marker org-clock-marker (point) (buffer-base-buffer))
 	    (move-marker org-clock-marker (point) (buffer-base-buffer))
@@ -1327,8 +1327,8 @@ for a todo state to switch to, overriding the existing value
       (org-clock-in (org-clock-select-task))
       (org-clock-in (org-clock-select-task))
     (let ((start-time (if (or org-clock-continuously (equal arg '(16)))
     (let ((start-time (if (or org-clock-continuously (equal arg '(16)))
 			  (or org-clock-out-time
 			  (or org-clock-out-time
-			      (org-current-time org-clock-rounding-minutes))
-			(org-current-time org-clock-rounding-minutes))))
+			      (org-current-time org-clock-rounding-minutes t))
+			(org-current-time org-clock-rounding-minutes t))))
       (if (null org-clock-history)
       (if (null org-clock-history)
 	  (message "No last clock")
 	  (message "No last clock")
 	(let ((org-clock-in-switch-to-state
 	(let ((org-clock-in-switch-to-state

+ 13 - 8
lisp/org.el

@@ -5324,18 +5324,23 @@ The following commands are available:
 		      (list (face-foreground 'org-hide))))))
 		      (list (face-foreground 'org-hide))))))
     (car (remove nil candidates))))
     (car (remove nil candidates))))
 
 
-(defun org-current-time (&optional rounding-minutes)
+(defun org-current-time (&optional rounding-minutes past)
   "Current time, possibly rounded to ROUNDING-MINUTES.
   "Current time, possibly rounded to ROUNDING-MINUTES.
 When ROUNDING-MINUTES is not an integer, fall back on the car of
 When ROUNDING-MINUTES is not an integer, fall back on the car of
-`org-time-stamp-rounding-minutes'."
+`org-time-stamp-rounding-minutes'.  When PAST is non-nil, ensure
+the rounding returns a past time."
   (let ((r (or (and (integerp rounding-minutes) rounding-minutes)
   (let ((r (or (and (integerp rounding-minutes) rounding-minutes)
 	       (car org-time-stamp-rounding-minutes)))
 	       (car org-time-stamp-rounding-minutes)))
-	(time (decode-time)))
-    (if (> r 1)
-	(apply 'encode-time
-	       (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r)))))
-		       (nthcdr 2 time)))
-      (current-time))))
+	(time (decode-time)) res)
+    (if (< r 1)
+	(current-time)
+      (setq res
+	    (apply 'encode-time
+		   (append (list 0 (* r (floor (+ .5 (/ (float (nth 1 time)) r)))))
+			   (nthcdr 2 time))))
+      (if (and past (< (time-to-seconds (time-subtract (current-time) res)) 0))
+	  (seconds-to-time (- (time-to-seconds res) (* r 60)))
+	res))))
 
 
 (defun org-today ()
 (defun org-today ()
   "Return today date, considering `org-extend-today-until'."
   "Return today date, considering `org-extend-today-until'."