Hi, Michael,
First, I just realized I was part wrong: vsum of time values DOES work
(sorry, Eric!).
| Task 1 | Task 2 | Task 3 | Total |
|--------+--------+--------+---------|
| 35:00 | 35:00 | 4:00 | 1:14:00 |
#+TBLFM: @2$4=vsum($1..$3);T
| Task | Time |
|--------+-------|
| Task 1 | 35:00 |
| Task 2 | 35:00 |
| Task 3 | 4:00 |
|--------+-------|
| Total | 1:14 |
#+TBLFM: @5$2=vsum(@I..@II);T
But in the vertical vsum in the second example above, the right answer
is misleadingly formatted, so you'd read it as 1 min 14 seconds, not 1
hr 14 mins.
And I'm still failing to get the right vsum /vertically/ with times
one hour or above, e.g.:
| Task | Time |
|--------+---------|
| Task 1 | 1:35:00 |
| Task 2 | 1:35:00 |
| Task 3 | 1:04:00 |
|--------+---------|
| Total | 3 |
#+TBLFM: @5$2=vsum(@I..@II);T
Meanwhile, Michael, thanks for your elisp solution -- it's more
compact than mine, and I'll be happy to steal it!
But support for time calculations -- in calc formulas too -- has been
added in 7.6.
Yours,
Christian
On 7/17/11 2:27 PM, Michael Markert wrote:
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(@I..@II);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 '(@I..@II))
Hope that helps.
Maybe there is an easier way. I hope there is ;)
Michael