From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre-Henry Frohring Subject: org-clock-time% does not parse "1d 12:50". This is a fix. (org-mode 8.1.1) Date: Mon, 9 Sep 2013 20:10:20 +0200 Message-ID: Mime-Version: 1.0 (Apple Message framework v1283) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ5uy-0006fQ-9s for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 14:10:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJ5up-0004wV-S4 for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 14:10:32 -0400 Received: from mail-wg0-x236.google.com ([2a00:1450:400c:c00::236]:57210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJ5up-0004wK-L8 for emacs-orgmode@gnu.org; Mon, 09 Sep 2013 14:10:23 -0400 Received: by mail-wg0-f54.google.com with SMTP id e11so4516085wgh.33 for ; Mon, 09 Sep 2013 11:10:22 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Dear all, While I was experimenting with clock tables #+BEGIN: clocktable :maxlevel 2 :scope file :formula % I found a surprising result : if *total time* is formatted as "1d 12:50" = then the percentages column gives wrong results. =20 The reason is that org-clock-time% does not take "1d 12:50" format into = account but only "12:50" format. You will find my fix of org-clock-time% below. Thank you. PH my version ---- (defun org-clock-time% (total &rest strings) "Compute a time fraction in percent. TOTAL is a time string like '1d 10:21' specifying the total times. STRINGS is a list of strings that should be checked for a time. The first string that does have a time will be used. This function is made for clock tables." (let ((re "\\(\\([0-9]+\\)d[[:space:]]\\)?\\([0-9]+\\):\\([0-9]+\\)") clock-str-to-minutes (tot 0) s) ;; "00:10" -> 10 ;; "5d 00:00" -> 7200 (setq clock-str-to-minutes (lambda (clock) (let ((minutes 0) (hours 0) (days 0) (tot 0)) (save-match-data (catch 'exit (if (not (string-match re clock)) ;; ill formatted =3D> 0 (throw 'exit 0.) ;; parse minutes, hours, days (setq minutes (string-to-number (match-string 4 = clock))) (setq hours (string-to-number (match-string 3 = clock))) (if (match-string 2 clock) (setq days (string-to-number (match-string 2 = clock)))) ;; compute the time in minutes (setq tot (+ minutes (* 60 hours) (* 60 24 = days))))))))) ;; compute time fraction in percent (save-match-data (catch 'exit (setq tot (funcall clock-str-to-minutes total)) (if (=3D tot 0.) (throw 'exit 0.)) (while (setq s (pop strings)) (throw 'exit (/ (* 100.0 (funcall clock-str-to-minutes s)) tot))) 0)))) original version : org-8.1.1/lisp/org-clock.el ---- (defun org-clock-time% (total &rest strings) "Compute a time fraction in percent. TOTAL s a time string like 10:21 specifying the total times. STRINGS is a list of strings that should be checked for a time. The first string that does have a time will be used. This function is made for clock tables." (let ((re "\\([0-9]+\\):\\([0-9]+\\)") tot s) (save-match-data (catch 'exit (if (not (string-match re total)) (throw 'exit 0.) (setq tot (+ (string-to-number (match-string 2 total)) (* 60 (string-to-number (match-string 1 = total))))) (if (=3D tot 0.) (throw 'exit 0.))) (while (setq s (pop strings)) (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s) (throw 'exit (/ (* 100.0 (+ (string-to-number (match-string 2 = s)) (* 60 (string-to-number (match-string 1 s))))) tot)))) 0))))