From mboxrd@z Thu Jan 1 00:00:00 1970 From: marco paolo valerio vezzoli Subject: Re: patch proposal for org-clock-time% with day Date: Mon, 18 Nov 2013 15:13:12 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b5d45d0f31e5304eb7425a6 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViPZl-0001ej-Oj for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 09:13:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ViPZh-0000aW-1K for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 09:13:17 -0500 Received: from mail-vc0-x22a.google.com ([2607:f8b0:400c:c03::22a]:36405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViPZg-0000aL-Qv for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 09:13:12 -0500 Received: by mail-vc0-f170.google.com with SMTP id ht10so1014297vcb.1 for ; Mon, 18 Nov 2013 06:13:12 -0800 (PST) In-Reply-To: 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 --047d7b5d45d0f31e5304eb7425a6 Content-Type: text/plain; charset=UTF-8 Another small patch: this handles also partial times > 1d. Marco (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 ((day-re "\\([0-9]+\\)d \\([0-9]+\\):\\([0-9]+\\)") (re "\\([0-9]+\\):\\([0-9]+\\)") tot s) (save-match-data (catch 'exit (if (not (string-match day-re total)) (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)))))) (setq tot (+ (string-to-number (match-string 2 total)) (* 60 (string-to-number (match-string 1 total))) (* 60 24 (string-to-number (match-string 1 total))))) (if (= tot 0.) (throw 'exit 0.))) (while (setq s (pop strings)) (if (string-match day-re s) (throw 'exit (/ (* 100.0 (+ (string-to-number (match-string 3 s)) (* 60 (string-to-number (match-string 2 s))) (* 60 24 (string-to-number (match-string 1 s))))) tot)) (if (string-match re s) (throw 'exit (/ (* 100.0 (+ (string-to-number (match-string 2 s)) (* 60 (string-to-number (match-string 1 s))))) tot))))) 0)))) 2013/11/18 marco paolo valerio vezzoli > Hi, > I use clocktables with the :funciton % option. > Sometime the table sums up to a time interval larger than one day so the > total may fool the regular expression: > > 1d 0:04 -> 4 minutes instead of 1444 minutes > > I wrote a simple modification of org-clock-time% : please find it below. > I'm sure that elisp wizards can find a better solution than mine. > Marco > > (defun org-clock-time% (total &rest strings) > "Compute a time fraction in percent. > TOTAL s 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 ((day-re "\\([0-9]+\\)d \\([0-9]+\\):\\([0-9]+\\)") > (re "\\([0-9]+\\):\\([0-9]+\\)") > tot s) > (save-match-data > (catch 'exit > (if (not (string-match day-re total)) > (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)))))) > (setq tot (+ (string-to-number (match-string 2 total)) > (* 60 (string-to-number (match-string 1 total))) > (* 60 24 (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)))) > --047d7b5d45d0f31e5304eb7425a6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding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