emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martin Halder <martin.halder@gmail.com>
To: mail@christianmoe.com
Cc: emacs-orgmode@gnu.org
Subject: Re: org table calc and lisp for hh:mm timetable
Date: Wed, 16 Mar 2011 10:22:34 +0100	[thread overview]
Message-ID: <00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com> (raw)
In-Reply-To: <4D7FDE8C.1030103@christianmoe.com>

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 = 100m = 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='(hms (+ (- (sec $5) (sec $4)) (- (sec $3) (sec $2))))::$7='(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,
> 
> This is ingenious! But I have a different solution that borrows conversion functions from org-timer.el.
> 
> 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.
> 
> #+begin_src emacs-lisp
>  (defun sec (arg)
>    (org-timer-hms-to-secs arg))
> 
>  (defun hms (arg)
>    (org-timer-secs-to-hms arg))
> #+end_src
> 
> Now, just do this:
> 
> |    Start |    Lunch |     Back |      End |  Sum    |
> |----------+----------+----------+----------+---------|
> | 08:00:00 | 12:20:00 | 13:00:00 | 17:00:00 | 8:20:00 |
> #+TBLFM: $5='(hms (+ (- (sec $4) (sec $3)) (- (sec $2) (sec $1))))
> 
> 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:
> 
> #+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"))))
> 
>  (defun hms (arg)
>    (if (integerp (/ arg 60))
>        (substring (org-timer-secs-to-hms arg) 0 -3)
>      (org-timer-secs-to-hms arg)))
> #+end_src
> 
> 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:
> 
> | Start | Lunch |  Back |   End |  Sum |
> |-------+-------+-------+-------+------|
> | 08:00 | 12:20 | 13:00 | 17:00 | 8:20 |
> #+TBLFM: $5='(hms (+ (- (sec $4) (sec $3)) (- (sec $2) (sec $1))))

  reply	other threads:[~2011-03-16  9:22 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 [this message]
2011-03-17  7:49         ` Bastien
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=00BD91C6-C610-4CDD-B3E0-E9FECDAA372C@gmail.com \
    --to=martin.halder@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@christianmoe.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).