From 805891523c466643f2efa9c2d5561fdfa8862e7c Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 1 May 2012 17:47:13 +0200 Subject: [PATCH] Fix bugs about computing durations in the column view. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 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. --- lisp/org-colview.el | 8 ++++++++ lisp/org.el | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 54097015c..030740217 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -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)) diff --git a/lisp/org.el b/lisp/org.el index 81da28961..877666404 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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 -- 2.11.4.GIT