From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre-Henry Frohring Subject: [BUG] org-time-clock% Date: Wed, 11 Sep 2013 14:42:05 +0200 Message-ID: <40DB3824-FBEA-4F93-81D7-CC0192AB8C35@gmail.com> Mime-Version: 1.0 (Apple Message framework v1283) Content-Type: multipart/mixed; boundary="Apple-Mail=_2EC85E92-5E15-46F3-AF11-13D102DEB56B" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJjkM-0005JE-Iu for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 08:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJjkL-0000lf-4z for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 08:42:14 -0400 Received: from mail-ea0-x22f.google.com ([2a00:1450:4013:c01::22f]:33994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJjkK-0000je-Qw for emacs-orgmode@gnu.org; Wed, 11 Sep 2013 08:42:13 -0400 Received: by mail-ea0-f175.google.com with SMTP id m14so4539552eaj.6 for ; Wed, 11 Sep 2013 05:42:08 -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 --Apple-Mail=_2EC85E92-5E15-46F3-AF11-13D102DEB56B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi ! org-time-clock% gives me unexpected result. =20 One could reproduce the bug using the code below or attached file. configuration : emacs-version : GNU Emacs 24.3.1 (x86_64-apple-darwin, NS = apple-appkit-1038.36) of 2013-03-13 on bob.porkrind.org org-version : Org-mode version 8.1.1 * results ** expected result #+BEGIN: clocktable :maxlevel 1 :scope file :formula % #+CAPTION: Clock summary at [2013-09-11 Mer 14:31] | Headline | Time | % | |--------------+-----------+-------| | *Total time* | *4d 0:00* | 100.0 | |--------------+-----------+-------| | task_1 | 2d 0:00 | 50.0 | | task_2 | 1d 0:00 | 25.0 | | task_3 | 1d 0:00 | 25.0 | #+TBLFM: $3=3D'(org-clock-time% @2$2 $2..$2);%.1f #+END: ** result obtained #+BEGIN: clocktable :maxlevel 1 :scope file :formula % #+CAPTION: Clock summary at [2013-09-11 Mer 14:39] | Headline | Time | % | |--------------+-----------+-----| | *Total time* | *4d 0:00* | 0.0 | |--------------+-----------+-----| | task_1 | 2d 0:00 | 0.0 | | task_2 | 1d 0:00 | 0.0 | | task_3 | 1d 0:00 | 0.0 | #+TBLFM: $3=3D'(org-clock-time% @2$2 $2..$2);%.1f #+END: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #+BEGIN: clocktable :maxlevel 1 :scope file :formula % #+CAPTION: Clock summary at [2013-09-11 Mer 14:31] | Headline | Time | % | |--------------+-----------+-------| | *Total time* | *4d 0:00* | 100.0 | |--------------+-----------+-------| | task_1 | 2d 0:00 | 50.0 | | task_2 | 1d 0:00 | 25.0 | | task_3 | 1d 0:00 | 25.0 | #+TBLFM: $3=3D'(org-clock-time% @2$2 $2..$2);%.1f #+END: * task_1 CLOCK: [2013-09-09 Lun 14:16]--[2013-09-11 Mer 14:16] =3D> 48:00 * task_2 CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] =3D> 24:00 * task_3 CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] =3D> 24:00 * org-clock-time% ** org-mode-8.1.1/lisp/org-clock.el #+BEGIN_SRC elisp (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)))) #+END_SRC #+RESULTS: : org-clock-time% ** fixed/org-clock-time% #+BEGIN_SRC elisp (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 (str-to-min (tot 0) s) ;; "([0-9]+d)? [0-9]+:[0-9]+" -> minutes (setq str-to-min (lambda (clock) (let ((re = "\\(\\([0-9]+\\)d[[:space:]]\\)?\\([0-9]+\\):\\([0-9]+\\)")) (save-match-data (catch 'exit (if (not (string-match re clock)) ;; ill formatted =3D> 0 (throw 'exit 0.) (+ (string-to-number (match-string 4 clock)) (* 60 (string-to-number (match-string 3 = clock))) (* 60 24 (if (match-string 2 clock) (string-to-number (match-string 2 = clock)) 0))))))))) ;; compute time fraction in percent (catch 'exit (setq tot (funcall str-to-min total)) (if (=3D tot 0.) (throw 'exit 0.)) (while (setq s (pop strings)) (throw 'exit (/ (* 100.0 (funcall str-to-min s)) tot))) 0))) #+END_SRC #+RESULTS: : org-clock-time% --Apple-Mail=_2EC85E92-5E15-46F3-AF11-13D102DEB56B Content-Disposition: attachment; filename=test-org-clocktable.org Content-Type: application/octet-stream; name="test-org-clocktable.org" Content-Transfer-Encoding: 7bit #+BEGIN: clocktable :maxlevel 1 :scope file :formula % #+CAPTION: Clock summary at [2013-09-11 Mer 14:19] | Headline | Time | % | |--------------+-----------+-----| | *Total time* | *4d 0:00* | 0.0 | |--------------+-----------+-----| | task_1 | 2d 0:00 | 0.0 | | task_2 | 1d 0:00 | 0.0 | | task_3 | 1d 0:00 | 0.0 | #+TBLFM: $3='(org-clock-time% @2$2 $2..$2);%.1f #+END: * task_1 CLOCK: [2013-09-09 Lun 14:16]--[2013-09-11 Mer 14:16] => 48:00 * task_2 CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00 * task_3 CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00 * org-clock-time% ** org-mode-8.1.1/lisp/org-clock.el #+BEGIN_SRC elisp (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 (= 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)))) #+END_SRC ** fixed/org-clock-time% #+BEGIN_SRC elisp (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 (str-to-min (tot 0) s) ;; "([0-9]+d)? [0-9]+:[0-9]+" -> minutes (setq str-to-min (lambda (clock) (let ((re "\\(\\([0-9]+\\)d[[:space:]]\\)?\\([0-9]+\\):\\([0-9]+\\)")) (save-match-data (catch 'exit (if (not (string-match re clock)) ;; ill formatted => 0 (throw 'exit 0.) (+ (string-to-number (match-string 4 clock)) (* 60 (string-to-number (match-string 3 clock))) (* 60 24 (if (match-string 2 clock) (string-to-number (match-string 2 clock)) 0))))))))) ;; compute time fraction in percent (catch 'exit (setq tot (funcall str-to-min total)) (if (= tot 0.) (throw 'exit 0.)) (while (setq s (pop strings)) (throw 'exit (/ (* 100.0 (funcall str-to-min s)) tot))) 0))) #+END_SRC --Apple-Mail=_2EC85E92-5E15-46F3-AF11-13D102DEB56B--