1

From a previous post (Calculate time range in org-mode table), I was able to use the org-evaluate-time-range function in a table.

I'd like to sum the obtained durations. However, searching for how to do that, I noticed the following behavior of TBLFM mode.

| <2015-12-09 01:29>--<2015-12-09 08:43> | 7 hours 14 minutes | 98 hours minutes |
| <2015-12-09 08:29>--<2015-12-09 08:43> | 14 minutes         | 14 minutes       |
#+TBLFM: $2='(org-evaluate-time-range)::$3=$2

Here in the third column, it seems that it is the product that is calculated. Any reason for that?

What I would like to is to sum the duration with a macro like that

#+TBLFM: $2='(org-evaluate-time-range)::@3$2=vsum(@1$2..@2$2)

Thanks.

Community
  • 1
  • 1
seacal
  • 17
  • 3

1 Answers1

2

The right-hand side of formulas like $3=$2 is evaluated by calc, and calc knows nothing about the 7 hour 14 minutes syntax. In fact, calc can do symbolic calculations, and it reads 7 hour 14 minutes as the product 7*hour*14*minutes where hour and minutes are variables.

The time syntax that calc understands is HH:MM[:SS]. This is illustrated by the org-mode manual.

TBLFM: has a flag ;T to format numeric values as time this way, but that does not work for timestamp ranges. So if you really want to start from a timestamp range, maybe one way is to write your own function to convert ranges to seconds:

Evaluate this first:
#+BEGIN_SRC emacs-lisp
  (defun convert-time-range-to-seconds (range)
    (if (string-match org-tr-regexp-both range)
        (let ((start (match-string 1 range))
              (end (match-string 2 range)))
          (round (- (org-time-string-to-seconds end)
                    (org-time-string-to-seconds start))))
      ""))
#+END_SRC

| time stamp range                               | as seconds |   as time |
|------------------------------------------------+------------+-----------|
| <2015-12-09 Wed 01:29>--<2015-12-10 Thu 08:42> |     112380 |  31:13:00 |
| <2015-12-28 Mon>--<2015-12-31 Thu>             |     259200 |  72:00:00 |
| <2015-12-11 Fri>--<2015-12-13 Sun>             |     172800 |  48:00:00 |
|------------------------------------------------+------------+-----------|
|                                                |            | 151:13:00 |
#+TBLFM: $2='(convert-time-range-to-seconds $1)::$3=$2;T::@>$3=vsum(@2..@-1);T
adl
  • 15,627
  • 6
  • 51
  • 65