emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] patch proposal for org-clock-time% with day


From: marco paolo valerio vezzoli
Subject: [O] patch proposal for org-clock-time% with day
Date: Mon, 18 Nov 2013 12:33:29 +0100

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))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]