From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Calc: Multiply time (hours) with a float Date: Mon, 19 Sep 2016 11:33:41 -0400 Message-ID: <87zin352ga.fsf@gmail.com> References: <2016-09-08T10-32-27@devnull.Karl-Voit.at> <2016-09-11T13-43-22@devnull.Karl-Voit.at> <87oa3u1vpn.fsf@luisa.c0t0d0s0.de> <2016-09-18T18-32-24@devnull.Karl-Voit.at> <874m5cs7tq.fsf@luisa.c0t0d0s0.de> <87oa3kqsy3.fsf@luisa.c0t0d0s0.de> <2016-09-19T13-38-25@devnull.Karl-Voit.at> <87a8f4m596.fsf@luisa.c0t0d0s0.de> <2016-09-19T14-57-54@devnull.Karl-Voit.at> <87shswkniq.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm0aM-0006Zh-Fh for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 11:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bm0aH-00078r-CD for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 11:34:21 -0400 Received: from [195.159.176.226] (port=39528 helo=blaine.gmane.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bm0aH-00076y-5G for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 11:34:17 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bm0Zw-0003FM-Od for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 17:33:56 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Michael Welle writes: > Hello, > > Karl Voit writes: > >> * Michael Welle wrote: >>> >>> Karl Voit writes: >>> >>>>> [...] >>>>>> #+TBLFM: @2$3='(* $2 (org-time-string-to-hours "$1"));L >>>>> or converting $2 to a number before the calculation should work also, >>>>> but is more to write ;). >>>> >>>> Hm. I still got #ERROR. I reduced my issue to calculate the float (for hours) >>>> without multiplying it with "value": >>> strange. I use the current Org version from git and Emacs 25.1. >>> >>>> | time [h:m:s] | value | product | >>>> |--------------+---------+---------| >>>> | 09:15:00 | 2.54321 | #ERROR | >>>> >>>> #+TBLFM: @2$3='(org-time-string-to-hours $1) >>> That works for me. The default interpretation of $1 is used and >>> therefore the value is fed into o-t-s-t-h as string. >> >> OK, this is my current issue then. FWIW, I used the above table with the definitions in an org file, C-C C-c'd the code, and C-c C-c'd the table formula - I get no error: --8<---------------cut here---------------start------------->8--- * table error strange. I use the current Org version from git and Emacs 25.1. | time [h:m:s] | value | product | |--------------+---------+---------| | 09:15:00 | 2.54321 | 9.25 | #+TBLFM: @2$3='(org-time-string-to-hours $1) * code #+BEGIN_SRC elisp (defun org-time-string-to-seconds (s) "Convert a string HH:MM:SS to a number of seconds. Omitted third element will be interpreted as MM:SS with missing hours." ;; test with: ;; (message (concat "result is: " (number-to-string (org-time-string-to-seconds "57:45:03")))) ;; (message (concat "result is: " (number-to-string (org-time-string-to-seconds "57:45")))) (cond ((and (stringp s) (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))) ((and (stringp s) (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)) (let ((min (string-to-number (match-string 1 s))) (sec (string-to-number (match-string 2 s)))) (+ (* min 60) sec))) ;;((stringp s) (string-to-number s)) ;;(t s) ) ) (defun org-time-string-to-hours (s) "Convert a string HH:MM:SS to hours (float). When only two values given, they will be interpreted as MM:SS with missing hours." ;; test via: ;; (message (concat "result is: " (number-to-string (org-time-string-to-hours "57:45:03")))) ;; (message (concat "result is: " (number-to-string (org-time-string-to-hours "57:45")))) (/ (org-time-string-to-seconds s) 3600.0) ) #+END_SRC #+RESULTS: : org-time-string-to-hours --8<---------------cut here---------------end--------------->8--- Org-mode version 8.3.6 (release_8.3.6-1135-g0ba465 GNU Emacs 25.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.9) of 2016-08-31 -- Nick