Fix bugs about computing durations in the column view.

* org-colview.el (org-columns-string-to-number): When
computing the values for the colview, match durations and
convert them to HH:MM values.

* org.el (org-duration-string-to-minutes): Match non-round
numbers.  Add a new optional parameter to allow returning the
output as a string.

Thanks to Sébastien for reporting these bugs.
This commit is contained in:
Bastien Guerry 2012-05-01 17:47:13 +02:00
parent 4d65272e03
commit 805891523c
2 changed files with 12 additions and 3 deletions

View File

@ -1083,6 +1083,14 @@ Don't set this, this is meant for dynamic scoping.")
(while l
(setq sum (+ (string-to-number (pop l)) (/ sum 60))))
sum))
((string-match (concat "\\([0-9.]+\\) *\\("
(regexp-opt (mapcar 'car org-effort-durations))
"\\)") s)
(setq s (concat "0:" (org-duration-string-to-minutes s t)))
(let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
(while l
(setq sum (+ (string-to-number (pop l)) (/ sum 60))))
sum))
((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
(if (equal s "[X]") 1. 0.000001))
((memq fmt '(estimate)) (org-string-to-estimate s))

View File

@ -16368,7 +16368,7 @@ effort string \"2hours\" is equivalent to 120 minutes."
:type '(alist :key-type (string :tag "Modifier")
:value-type (number :tag "Minutes")))
(defun org-duration-string-to-minutes (s)
(defun org-duration-string-to-minutes (s &optional output-to-string)
"Convert a duration string S to minutes.
A bare number is interpreted as minutes, modifiers can be set by
@ -16377,15 +16377,16 @@ customizing `org-effort-durations' (which see).
Entries containing a colon are interpreted as H:MM by
`org-hh:mm-string-to-minutes'."
(let ((result 0)
(re (concat "\\([0-9]+\\) *\\("
(re (concat "\\([0-9.]+\\) *\\("
(regexp-opt (mapcar 'car org-effort-durations))
"\\)")))
(while (string-match re s)
(incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
(string-to-number (match-string 1 s))))
(setq s (replace-match "" nil t s)))
(setq result (floor result))
(incf result (org-hh:mm-string-to-minutes s))
result))
(if output-to-string (number-to-string result) result)))
;;;; Files