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: Martin Halder
Subject: Re: [O] org table calc and lisp for hh:mm timetable
Date: Wed, 16 Mar 2011 10:22:34 +0100

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 via email to

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