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.vezz...@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))))
>

Reply via email to