* org-clock-time% does not parse "1d 12:50". This is a fix. (org-mode 8.1.1)
@ 2013-09-09 18:10 Pierre-Henry Frohring
0 siblings, 0 replies; only message in thread
From: Pierre-Henry Frohring @ 2013-09-09 18:10 UTC (permalink / raw)
To: emacs-orgmode
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.
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 => 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 (= 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 (= 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))))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-09-09 18:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09 18:10 org-clock-time% does not parse "1d 12:50". This is a fix. (org-mode 8.1.1) Pierre-Henry Frohring
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).