From: Bastien <bzg@altern.org>
To: Martin Halder <martin.halder@gmail.com>
Cc: emacs-orgmode@gnu.org, mail@christianmoe.com
Subject: Re: org table calc and lisp for hh:mm timetable
Date: Thu, 17 Mar 2011 08:49:22 +0100 [thread overview]
Message-ID: <87k4fynog3.fsf@altern.org> (raw)
In-Reply-To: <00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com> (Martin Halder's message of "Wed, 16 Mar 2011 10:22:34 +0100")
Hi Martin,
Martin Halder <martin.halder@gmail.com> 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
next prev parent reply other threads:[~2011-03-17 10:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 18:32 org table calc and lisp for hh:mm timetable Martin Halder
2011-03-15 19:22 ` Eric S Fraga
2011-03-15 19:49 ` Martin Halder
2011-03-15 20:37 ` Eric S Fraga
2011-03-15 21:47 ` Christian Moe
2011-03-16 9:22 ` Martin Halder
2011-03-17 7:49 ` Bastien [this message]
2011-03-20 17:50 ` Eric Schulte
2011-03-20 19:57 ` Eric S Fraga
2011-03-20 17:50 ` Eric Schulte
2011-03-20 21:00 ` Christian Moe
2011-03-20 23:43 ` Eric Schulte
2011-03-22 4:40 ` Eric Schulte
2011-03-22 9:36 ` Christian Moe
2011-03-24 1:18 ` Eric Schulte
2011-03-24 18:35 ` Martin Halder
2011-03-22 10:52 ` Carsten Dominik
2011-07-02 11:38 ` Bastien
2011-03-16 9:28 ` Eric S Fraga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k4fynog3.fsf@altern.org \
--to=bzg@altern.org \
--cc=emacs-orgmode@gnu.org \
--cc=mail@christianmoe.com \
--cc=martin.halder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).