From: marco paolo valerio vezzoli <marco.p.v.vezzoli@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: patch proposal for org-clock-time% with day
Date: Mon, 18 Nov 2013 15:13:12 +0100 [thread overview]
Message-ID: <CAGb6wsqHs1tOyLhBHd5r2MRZgzqtOupd9AkaxpTzNLQPJfcsDw@mail.gmail.com> (raw)
In-Reply-To: <CAGb6wso41mFYGX5ESMts5Xt2oTko9XRpGBO3V6RSi=Z67Z3_Cg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3341 bytes --]
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 <marco.p.v.vezzoli@gmail.com>
> 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))))
>
[-- Attachment #2: Type: text/html, Size: 4488 bytes --]
next prev parent reply other threads:[~2013-11-18 14:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-18 11:33 patch proposal for org-clock-time% with day marco paolo valerio vezzoli
2013-11-18 14:13 ` marco paolo valerio vezzoli [this message]
2013-11-19 9:31 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGb6wsqHs1tOyLhBHd5r2MRZgzqtOupd9AkaxpTzNLQPJfcsDw@mail.gmail.com \
--to=marco.p.v.vezzoli@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).