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

[-- Attachment #1: Type: text/plain, Size: 1589 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2011-07-17 12:27 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 [this message]
2011-07-17 13:27   ` Christian Moe
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=87wrfhum6g.wl%markert.michael@googlemail.com \
    --to=markert.michael@googlemail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@christianmoe.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).