emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org table calc and lisp for hh:mm timetable


From: Bastien
Subject: Re: [O] org table calc and lisp for hh:mm timetable
Date: Thu, 17 Mar 2011 08:49:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Hi Martin,

Martin Halder <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]