[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Time calculation: vsum?
From: |
Michael Markert |
Subject: |
Re: [O] Time calculation: vsum? |
Date: |
Sun, 17 Jul 2011 14:27:35 +0200 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) Emacs/23.3 Mule/6.0 (HANACHIRUSATO) |
Hi Christian,
On 17 Jul 2011, Christian Moe wrote:
> Hi,
>
> Time calculations don't seem to work with vsum (or vmean).
>
>
> | Time |
> |---------|
> | 1:06:00 |
> | 0:52:30 |
> | 2:00:00 |
> |---------|
> | 3 |
> #+TBLFM: @5$1=vsum(@address@hidden);T
>
>
> Am I doing something wrong?
Yes, `vsum' works just on numbers, not times.
> Could this be made to work?
Here's a elisp function that does what you want (assuming it's
hours:minutes:seconds -- if not tweak the numbers):
#+begin_src elisp
(defun h-m-s-vsum (times)
(loop for (h m s) in (mapcar (lambda (time)
(mapcar #'string-to-int
(split-string time ":" 'omit-nulls)))
times)
collect (+ (* 3600 h) (* 60 m) s) into seconds
finally (return (let* ((second-sum (apply #'+ seconds))
(seconds (let ((s (% second-sum 60)))
(decf second-sum s)
s))
(minutes (let ((m (% second-sum 3600)))
(decf second-sum m)
(truncate (/ m 60))))
(hours (/ second-sum 3600)))
(format "%s:%s:%s" hours minutes seconds)))))
#+end_src elisp
The table has to be
| Time |
|---------|
| 1:06:00 |
| 0:52:30 |
| 2:00:00 |
|---------|
| 3:58:30 |
#+TBLFM: @5$1='(h-m-s-vsum '(@address@hidden))
Hope that helps.
Maybe there is an easier way. I hope there is ;)
Michael
pgpKhBzr54pEs.pgp
Description: PGP signature