From a3c366eb98f029315b252212fb8764714249b092 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 11 Nov 2016 12:02:34 +0100 Subject: [PATCH] org-colview: Fix time sum when mixing duration and H:MM:SS time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/org-colview.el (org-columns--time-to-seconds): Recognize a duration even when it contains a H:MM:SS part. * testing/lisp/test-org-colview.el (test-org-colview/columns-summary): Add test. Reported-by: Björn Döring --- lisp/org-colview.el | 6 +++--- testing/lisp/test-org-colview.el | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lisp/org-colview.el b/lisp/org-colview.el index d33f50579..5223902dc 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1068,12 +1068,12 @@ This function updates `org-columns-current-fmt-compiled'." A time is expressed as HH:MM, HH:MM:SS, or with units defined in `org-effort-durations'. Plain numbers are considered as hours." (cond - ((string-match "\\([0-9]+\\):\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?" s) + ((string-match-p org-columns--duration-re s) + (* 60 (org-duration-string-to-minutes s))) + ((string-match "\\`\\([0-9]+\\):\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?\\'" s) (+ (* 3600 (string-to-number (match-string 1 s))) (* 60 (string-to-number (match-string 2 s))) (if (match-end 3) (string-to-number (match-string 3 s)) 0))) - ((string-match-p org-columns--duration-re s) - (* 60 (org-duration-string-to-minutes s))) (t (* 3600 (string-to-number s))))) (defun org-columns--age-to-seconds (s) diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index f81dfa144..8b312ab12 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -471,7 +471,8 @@ (let ((org-columns-default-format "%A{@mean}")) (org-columns)) (get-char-property (point) 'org-columns-value-modified))))) ;; If a time value is expressed as a duration, return a duration. - ;; If any of them follows H:MM:SS pattern, use it too. + ;; If any of them follows H:MM:SS pattern, use it too. Also handle + ;; combinations of duration and H:MM:SS patterns. (should (equal "1d 4:20" @@ -506,6 +507,25 @@ :END:" (let ((org-columns-default-format "%A{:}")) (org-columns)) (get-char-property (point) 'org-columns-value-modified)))) + (should + (equal + "1d 4:20" + (org-test-with-temp-text + "* H +** S1 +:PROPERTIES: +:A: 3d 3h +:END: +** S1 +:PROPERTIES: +:A: 0d 1:20 +:END:" + (let ((org-columns-default-format "%A{:}") + (org-time-clocksum-use-fractional nil) + (org-time-clocksum-format + '(:days "%dd " :hours "%d" :minutes ":%02d"))) + (org-columns)) + (get-char-property (point) 'org-columns-value-modified)))) ;; @min, @max and @mean also accept regular duration in ;; a "?d ?h ?m ?s" format. (should