From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric S Fraga Subject: Re: org table calc and lisp for hh:mm timetable Date: Tue, 15 Mar 2011 19:22:32 +0000 Message-ID: <87lj0gqjd3.fsf@ucl.ac.uk> References: <9999237C-1FBD-481E-AF8D-D68DB85080CE@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=53833 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzZpX-00073r-Qr for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 15:22:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzZpW-0007Da-Jp for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 15:22:55 -0400 Received: from vscane-b.ucl.ac.uk ([144.82.108.141]:48021) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzZpW-0007DB-CH for emacs-orgmode@gnu.org; Tue, 15 Mar 2011 15:22:54 -0400 In-Reply-To: <9999237C-1FBD-481E-AF8D-D68DB85080CE@gmail.com> (Martin Halder's message of "Tue, 15 Mar 2011 19:32:24 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Martin Halder Cc: emacs-orgmode@gnu.org Martin Halder writes: > Hi all, > > some words of warning: this was written by an Emacs, Org, Lisp and > Calc newbie.. and congratulations on converting a vim user btw, org > mode is great : ) > > I was trying to generate a simple table with time format "hh:mm" and > auto calculate daily sum.. clocking working time was too much so I > thought this would be easy but ended up with the following.. it works > but is not beautiful (apply formula twice and same information > multiple times) and I would like to get rid of the "hms", "hh" and > "mm" columns and therefore call "hmconcat" directly somehow.. Any help > is highly appreciated.. > > Thanks, > Martin > > | Date | Start | Lunch | Back | End | Sum | hms | hh | mm | > |------------------+-------+-------+-------+-------+-------+-----------+----+----| > | [2011-03-01 Tue] | 08:00 | 12:20 | 13:00 | 17:00 | 08:20 | 8@ 20' 0" | 8 | 20 | > #+TBLFM: $6='(hmconcat $8 $9)::$7=time(<2010-01-01 $5>)-time(<2010-01-01 $4>)+time(<2010-01-01 $3>)-time(<2010-01-01 $2>)::$8=hour($7)::$9=minute($7) > > (defun hmconcat (hh mm) (interactive) > (if (> (length hh) 1) > (setq temp (concat hh ":")) (setq temp (concat "0" hh ":"))) > (if (> (length mm) 1) > (concat temp mm) (concat temp "0" mm))) Martin, glad to see you got further with this! You can definitely get rid of hmconcat by using a combination of string-to-number and format (and I'm sure it's possible to get this done with simpler elisp): --8<---------------cut here---------------start------------->8--- | Date | Start | Lunch | Back | End | Sum | hms | hh | mm | |------------------+-------+-------+-------+-------+-------+-----------+----+----| | [2011-03-01 Tue] | 08:00 | 12:20 | 13:00 | 17:00 | 08:20 | 8@ 20' 0" | 8 | 20 | #+TBLFM: $6='(format "%02d:%02d" (string-to-number $8) (string-to-number $9))::$7=time(<2010-01-01 $5>)-time(<2010-01-01 $4>)+time(<2010-01-01 $3>)-time(<2010-01-01 $2>)::$8=hour($7)::$9=minute($7) --8<---------------cut here---------------end--------------->8--- -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.52.g0dc16.dirty)