emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rainer Stengele <rainer.stengele@online.de>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: executing org-table TBLFM form changes (resets) language settings
Date: Mon, 5 Mar 2018 15:39:08 +0100	[thread overview]
Message-ID: <a064308a-84f4-a47a-71a1-bc53c4067213@online.de> (raw)
In-Reply-To: <87372mxp42.fsf@nicolasgoaziou.fr>

Am 31.01.2018 um 12:08 schrieb Nicolas Goaziou:
> Hello,
> 
> Rainer Stengele <rainer.stengele@online.de> 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")))))

      reply	other threads:[~2018-03-05 14:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25 13:30 executing org-table TBLFM form changes (resets) language settings Rainer Stengele
2018-01-25 19:27 ` Nick Dokos
2018-01-26  9:46   ` Rainer Stengele
2018-01-29  7:49     ` Rainer Stengele
2018-01-30 19:45       ` Rainer Stengele
2018-01-30 21:07         ` Nicolas Goaziou
2018-01-31  9:45           ` Rainer Stengele
2018-01-31 11:08             ` Nicolas Goaziou
2018-03-05 14:39               ` Rainer Stengele [this message]

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=a064308a-84f4-a47a-71a1-bc53c4067213@online.de \
    --to=rainer.stengele@online.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /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).