diff options
author | Bastien Guerry <bzg@altern.org> | 2013-02-19 12:40:33 +0100 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2013-02-19 12:40:33 +0100 |
commit | d1e57bd884f5285e40e0bbae60483aac93657cab (patch) | |
tree | 130fd304bbcfea8d5f8ae8569580cd59a9d4a2f8 | |
parent | 8a910bd40b182fac1e2f2c76502d9f0b556d1716 (diff) | |
download | org-mode-d1e57bd884f5285e40e0bbae60483aac93657cab.tar.gz |
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.
-rw-r--r-- | lisp/org-clock.el | 8 | ||||
-rw-r--r-- | lisp/org.el | 21 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 1bf53c3..2c56147 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -1271,11 +1271,11 @@ make this the default behavior.)" (format "You stopped another clock %d mins ago; start this one from then? " (/ (- (org-float-time - (org-current-time org-clock-rounding-minutes)) + (org-current-time org-clock-rounding-minutes t)) (org-float-time leftover)) 60))) leftover) 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 'with-hm 'inactive)))) (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)) (let ((start-time (if (or org-clock-continuously (equal arg '(16))) (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) (message "No last clock") (let ((org-clock-in-switch-to-state diff --git a/lisp/org.el b/lisp/org.el index f19f48d..32797a1 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5324,18 +5324,23 @@ The following commands are available: (list (face-foreground 'org-hide)))))) (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. 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) (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 () "Return today date, considering `org-extend-today-until'." |