[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] executing org-table TBLFM form changes (resets) language setting
From: |
Rainer Stengele |
Subject: |
Re: [O] executing org-table TBLFM form changes (resets) language settings |
Date: |
Mon, 5 Mar 2018 15:39:08 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
Am 31.01.2018 um 12:08 schrieb Nicolas Goaziou:
Hello,
Rainer Stengele <address@hidden> writes:
I set the variables in my .emacs:
(defvar math-short-weekday-names '( "So" "Mo" "Di" "Mi" "Do" "Fr" "Sa" ))
Shouldn't it be (setq math-short-weekday-names '("So" ...))
Very strange, no clue why that happens.
No clue either. Calc is pretty foreign to me. You may want to ask Emacs
devel ML.
Regards,
Hi,
as nobody answered my calc question neither here nor in the emacs user group I
am now using a work around.
I rearranged my timestamp table from
| IM Startzeit | IM Endezeit | Stunden | delta(x,16) |
Anm. |
|-----------------------+-----------------------+--------------+--------------+------|
| [2018-01-22 Mo 19:30] | [2018-01-23 Di 14:30] | 19.00 | 3.00 |
|
#+TBLFM: $3=24*(date(<$2>)-date(<$1>)); %.2f::$4=$3-16.0; %.2f
to
| IM Startzeit -- IM Endezeit | Stunden - Min String | Delta
| Anm. |
|----------------------------------------------+----------------------+--------+------------------------------------------|
| [2018-01-22 Mo 19:30]--[2018-01-23 Di 14:30] | 19.00 | 3.00
| |
#+TBLFM: $2='(rst/org-evaluate-time-range)::$3=$2-16.0; %.2f
I copied org-evaluate-time-range to rst/org-evaluate-time-range and modified the output slightly to give me a %2.2f hours based time range
delta. Brutal, but works.
Thank you.
Regards, Rainer
(defun rst/org-evaluate-time-range (&optional to-buffer)
"Evaluate a time range by computing the difference between start and end.
Normally the result is just printed in the echo area, but with prefix arg
TO-BUFFER, the result is inserted just after the date stamp into the buffer.
If the time range is actually in a table, the result is inserted into the
next column.
For time difference computation, a year is assumed to be exactly 365
days in order to avoid rounding problems."
(interactive "P")
(or
(org-clock-update-time-maybe)
(save-excursion
(unless (org-at-date-range-p t)
(goto-char (point-at-bol))
(re-search-forward org-tr-regexp-both (point-at-eol) t))
(unless (org-at-date-range-p t)
(user-error "Not at a time-stamp range, and none found in current
line")))
(let* ((ts1 (match-string 1))
(ts2 (match-string 2))
(havetime (or (> (length ts1) 15) (> (length ts2) 15)))
(match-end (match-end 0))
(time1 (org-time-string-to-time ts1))
(time2 (org-time-string-to-time ts2))
(t1 (float-time time1))
(t2 (float-time time2))
(diff (abs (- t2 t1)))
(negative (< (- t2 t1) 0))
;; (ys (floor (* 365 24 60 60)))
(ds (* 24 60 60))
(hs (* 60 60))
(fy "%dy %dd %02d:%02d")
(fy1 "%dy %dd")
(fd "%dd %02d:%02d")
(fd1 "%dd")
(fh "%02d:%02d")
y d h m align)
(if havetime
(setq ; y (floor (/ diff ys)) diff (mod diff ys)
y 0
d (floor (/ diff ds)) diff (mod diff ds)
h (floor (/ diff hs)) diff (mod diff hs)
m (floor (/ diff 60)))
(setq ; y (floor (/ diff ys)) diff (mod diff ys)
y 0
d (floor (+ (/ diff ds) 0.5))
h 0 m 0))
(if (not to-buffer)
;; RST changes here:
;; (message "%s" (org-make-tdiff-string y d h m))
(message "%2.2f" (+ (* 24 d) h (/ m 60.0)))
(if (org-at-table-p)
(progn
(goto-char match-end)
(setq align t)
(and (looking-at " *|") (goto-char (match-end 0))))
(goto-char match-end))
(when (looking-at
"\\( *-? *[0-9]+y\\)?\\( *[0-9]+d\\)? *[0-9][0-9]:[0-9][0-9]")
(replace-match ""))
(when negative (insert " -"))
(if (> y 0) (insert " " (format (if havetime fy fy1) y d h m))
(if (> d 0) (insert " " (format (if havetime fd fd1) d h m))
(insert " " (format fh h m))))
(when align (org-table-align))
(message "Time difference inserted")))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [O] executing org-table TBLFM form changes (resets) language settings,
Rainer Stengele <=