From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Markert Subject: Re: Time calculation: vsum? Date: Sun, 17 Jul 2011 14:27:35 +0200 Message-ID: <87wrfhum6g.wl%markert.michael@googlemail.com> References: <4E2278C6.1020407@christianmoe.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/signed; boundary="pgp-sign-Multipart_Sun_Jul_17_14:27:35_2011-1"; micalg=pgp-sha256; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:53205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiQRm-0001Kn-Ux for emacs-orgmode@gnu.org; Sun, 17 Jul 2011 08:27:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QiQRl-000772-E1 for emacs-orgmode@gnu.org; Sun, 17 Jul 2011 08:27:46 -0400 Received: from mail-ew0-f41.google.com ([209.85.215.41]:55271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiQRk-00076y-P2 for emacs-orgmode@gnu.org; Sun, 17 Jul 2011 08:27:45 -0400 Received: by ewy9 with SMTP id 9so1329061ewy.0 for ; Sun, 17 Jul 2011 05:27:42 -0700 (PDT) In-Reply-To: <4E2278C6.1020407@christianmoe.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: mail@christianmoe.com Cc: Org Mode --pgp-sign-Multipart_Sun_Jul_17_14:27:35_2011-1 Content-Type: text/plain; charset=US-ASCII 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 --pgp-sign-Multipart_Sun_Jul_17_14:27:35_2011-1 Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBCAAGBQJOItU3AAoJEHHMVUK0UjKViTgP/RzOO8JyOGIHxs7BHCQq8cY6 eLIhMhwr3sIXf2au6WbgksWz39VswtGQWjAa9TWwUgahoMEVBFrqcwPPJu0HIAr7 X9SIGxFOkfVo+1SrwF24nXBnZCytFusiuTG1OFFQkhbf51iJtqzzkawdyKDsLeAT 4KtRcfDWt+y0jM8cA49+TcQP1Wkx1l+MsDNdb5qo3BaWC4eHbGNkMvhuz35RW3zd 8PvN8ZDGtE1hrHRvCZSGkAaNbEkaX/uuDBTxWrOxVr0+78P2Z2UVqkfhsl8mWYDn hXxnBGTouTSOdRZIAn8NJIiTOzHx+RNNqUAhP9XIv8xaUsOGPRCPzm7dDHpNwEib NFH273Z2x+8/KAbblXydNI/7+zrpKgEG9tMUrCZxT06jQzmH3jfCwc2iZ0KMx7N8 LJdb/n2x+NdI18Bg5JGN/9zenlFP7kS2growClyBAMrmehZoI+bSuhwXH41CGA4l 4v8UmJAIhv9YUFVjwIpMiT8o+07LbYoz043P/mspp9RiXC5U95trwzUbYIxfvmhW GYM+t3SS1kA3QcrgNRNrikTJw5jCZlBR9nl0BmLmm/3nJ3RTWNaH2x/jqM7rGssU /Z/q7wKZxRgfvkMjNnXIBeVvQLQPSxN3LYL7N7RcKWFn812hfJVRNOYAUQTLAQDh KnsjjuCfmX1YXq4bEtFP =GoSX -----END PGP SIGNATURE----- --pgp-sign-Multipart_Sun_Jul_17_14:27:35_2011-1--