From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin Halder Subject: Re: org table calc and lisp for hh:mm timetable Date: Wed, 16 Mar 2011 10:22:34 +0100 Message-ID: <00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com> References: <9999237C-1FBD-481E-AF8D-D68DB85080CE@gmail.com> <87lj0gqjd3.fsf@ucl.ac.uk> <0DDD90AF-9B9A-4FE3-8080-74EF01E6E292@gmail.com> <4D7FDE8C.1030103@christianmoe.com> Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=58840 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzmwP-00018l-Lx for emacs-orgmode@gnu.org; Wed, 16 Mar 2011 05:22:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzmwK-00054r-5x for emacs-orgmode@gnu.org; Wed, 16 Mar 2011 05:22:49 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:58136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzmwK-00054l-0U for emacs-orgmode@gnu.org; Wed, 16 Mar 2011 05:22:48 -0400 Received: by wwc33 with SMTP id 33so1603778wwc.30 for ; Wed, 16 Mar 2011 02:22:47 -0700 (PDT) In-Reply-To: <4D7FDE8C.1030103@christianmoe.com> 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: mail@christianmoe.com Cc: emacs-orgmode@gnu.org Hi Christian, this is fantastic, already love lisp, thanks a lot.. now I have exactly = what I wanted.. additionally I needed the time format in industrial mode = (1h =3D 100m =3D 100s), implemented in ihms. Thanks, Martin | Date | Start | Lunch | Back | End | Sum | Ind | |------------------+-------+-------+-------+-------+------+------| | [2011-03-01 Tue] | 8:00 | 12:00 | 12:30 | 18:15 | 9:45 | 9.75 | #+TBLFM: $6=3D'(hms (+ (- (sec $5) (sec $4)) (- (sec $3) (sec = $2))))::$7=3D'(ihms (+ (- (sec $5) (sec $4)) (- (sec $3) (sec $2)))) (defun sec (arg) (if (string-match org-timer-re arg) (org-timer-hms-to-secs arg) (org-timer-hms-to-secs (concat arg ":00")))) (defun hms (s) (let (m h) (setq s (abs s) m (/ s 60) s (- s (* 60 m)) h (/ m 60) m (- m (* 60 h))) (format "%d:%02d" h m))) (defun ihms (s) (let (m h) (setq s (/ (* s 10000) 3600) s (abs s) m (/ s 100) s (- s (* 100 m)) h (/ m 100) m (- m (* 100 h))) (format "%d.%02d" h m))) Am 15.03.2011 um 22:47 schrieb Christian Moe: > Hi, >=20 > This is ingenious! But I have a different solution that borrows = conversion functions from org-timer.el. >=20 > To avoid an insanely long formula, I'll alias those functions with = shorter names which don't seem to colide with anything in my Emacs. >=20 > #+begin_src emacs-lisp > (defun sec (arg) > (org-timer-hms-to-secs arg)) >=20 > (defun hms (arg) > (org-timer-secs-to-hms arg)) > #+end_src >=20 > Now, just do this: >=20 > | Start | Lunch | Back | End | Sum | > |----------+----------+----------+----------+---------| > | 08:00:00 | 12:20:00 | 13:00:00 | 17:00:00 | 8:20:00 | > #+TBLFM: $5=3D'(hms (+ (- (sec $4) (sec $3)) (- (sec $2) (sec $1)))) >=20 > This already works for me, because my main interest here is in keeping = track of my jogging, but those seconds are spurious precision for your = use case, and take up space. So rewrite sec and hms: >=20 > #+begin_src emacs-lisp > (defun sec (arg) > (if (string-match org-timer-re arg) > (org-timer-hms-to-secs arg) > (org-timer-hms-to-secs (concat arg ":00")))) >=20 > (defun hms (arg) > (if (integerp (/ arg 60)) > (substring (org-timer-secs-to-hms arg) 0 -3) > (org-timer-secs-to-hms arg))) > #+end_src >=20 > Now sec will correctly convert hh:mm stamps, too, and hms will convert = to hh:mm format if the argument is in whole minutes, otherwise to = hh:mm:ss. So: >=20 > | Start | Lunch | Back | End | Sum | > |-------+-------+-------+-------+------| > | 08:00 | 12:20 | 13:00 | 17:00 | 8:20 | > #+TBLFM: $5=3D'(hms (+ (- (sec $4) (sec $3)) (- (sec $2) (sec $1))))