emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: Michael Markert <markert.michael@googlemail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: Time calculation: vsum?
Date: Sun, 17 Jul 2011 15:27:32 +0200	[thread overview]
Message-ID: <4E22E344.5050503@christianmoe.com> (raw)
In-Reply-To: <87wrfhum6g.wl%markert.michael@googlemail.com>

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

  reply	other threads:[~2011-07-17 13:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-17  5:53 Time calculation: vsum? Christian Moe
2011-07-17 12:27 ` Michael Markert
2011-07-17 13:27   ` Christian Moe [this message]
2011-07-24 18:32 ` Bastien
2011-07-24 22:03   ` Christian Moe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E22E344.5050503@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=markert.michael@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).