From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: org table calc and lisp for hh:mm timetable Date: Thu, 17 Mar 2011 08:49:22 +0100 Message-ID: <87k4fynog3.fsf@altern.org> References: <9999237C-1FBD-481E-AF8D-D68DB85080CE@gmail.com> <87lj0gqjd3.fsf@ucl.ac.uk> <0DDD90AF-9B9A-4FE3-8080-74EF01E6E292@gmail.com> <4D7FDE8C.1030103@christianmoe.com> <00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=37429 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0AJM-0007up-Ky for emacs-orgmode@gnu.org; Thu, 17 Mar 2011 06:20:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0AJK-0005aa-Qm for emacs-orgmode@gnu.org; Thu, 17 Mar 2011 06:20:08 -0400 Received: from mail-ww0-f67.google.com ([74.125.82.67]:53867) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0AJK-0005Wr-HO for emacs-orgmode@gnu.org; Thu, 17 Mar 2011 06:20:06 -0400 Received: by mail-ww0-f67.google.com with SMTP id 36so473508wwa.6 for ; Thu, 17 Mar 2011 03:20:06 -0700 (PDT) In-Reply-To: <00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com> (Martin Halder's message of "Wed, 16 Mar 2011 10:22:34 +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, mail@christianmoe.com Hi Martin, Martin Halder writes: > 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 = 100m = 100s), implemented in ihms. thanks for these functions -- I allowed myself to add them to Worg/org-hacks.html, in a new "Times computation" section: http://orgmode.org/worg/org-hacks.html I added these functions I myself wrote for a particular purpose: #+begin_src emacs-lisp (defun org-hh:mm:ss-string-to-seconds (s) "Convert a string HH:MM:SS to a number of seconds." (when (string-match "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)" s) (let ((hour (string-to-number (match-string 1 s))) (min (string-to-number (match-string 2 s))) (sec (string-to-number (match-string 3 s)))) (+ (* hour 3600) (* min 60) sec)))) (defun org-subtract-hh:mm:ss-time (t1 t2) "Substract two hh:mm:ss time values." (let* ((sec (- (org-hh:mm:ss-string-to-seconds t2) (org-hh:mm:ss-string-to-seconds t1))) (hour (floor (/ sec 3600))) (min (floor (/ (- sec (* 3600 hour)) 60))) (secs (round (- sec (* 3600 hour) (* 60 min))))) (format "%.2d:%.2d:%.2d" hour min secs))) #+end_src With these function, you can subtract durations in a table like this: | Part | Begin | End | Duration | |-------+----------+----------+----------| | One | 00:00:00 | 00:01:11 | 00:01:11 | | Two | 00:01:12 | 00:02:00 | 00:00:48 | | Three | 00:02:05 | 00:16:06 | 00:14:01 | #+TBLFM: $4='(org-subtract-hh:mm:ss-time $2 $3) Which was useful for me when I had to derush video files. HTH, -- Bastien