How to calculate time durations in tables?
Subtraction of numerical vectors works directly:
| day | t1 | t2 | differences |
|------------------+----------+----------+-------------|
| [2021-04-08 Thu] | [10, 13] | [16, 18] | [6, 5] |
#+TBLFM: $4=$3-$2
Using this with time vectors to compute durations doesn't work. It computes only the first item:
| day | time 1 | time 2 | durations |
|------------------+----------------+----------------+-----------|
| [2021-04-08 Thu] | [10:45, 14:00] | [12:00, 15:00] | 01:15 |
#+TBLFM: $4=$3-$2;U
I would expect this:
| day | time 1 | time 2 | durations |
|------------------+----------------+----------------+---------------|
| [2021-04-08 Thu] | [10:45, 14:00] | [12:00, 15:00] | [01:15, 1:00] |
I hope there is an (easy) solution (?)
EDIT: The n-th item of 'time 2' would be always larger than the n-th item of 'time1'. I don't know if this makes it simpler.
EDIT2: I've tried it with elisp. My idea was to convert the time into minutes, so 10:45 should be converted to 10x60+45=645. I've found an org function for it, the evaluation of the following line is "645.0".
(org-duration-to-minutes "10:45")
Then I can make the "vector subtraction" with the numbers, then I just have to reconvert the results. There is the function org-duration-from-minutes
for this purpose.
That was the idea but I wasn't able to let it work in the table. I'm not familiar at all with it. Even this simple formula doesn't work -- "ERROR":
| day | time 1 | time 2 | time2 in minutes | durations |
|------------------+----------------+----------------+------------------+-----------|
| [2021-04-08 Thu] | [10:45, 14:00] | [12:00, 14:00] | #ERROR | |
#+TBLFM: $4='(mapcar 'org-duration-to-minutes $3)
I would expect "[720.0, 840.0]". (This would be an intermediate step.) I also tried to change the format into "10:45 14:00" or "(10:45 14:00)" or "(10:45, 14:00)".. It didn't work.
EDIT 3: I've found a solution. See below.
U
format assumes that the element it is applied to is a scalar. I'd love to be proven wrong though.