emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Calc/TBLFM: how to conditionally insert hours:minutes?
@ 2023-09-23 19:38 Chris Keschnat
  2023-09-25  9:32 ` Bruno Barbier
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Keschnat @ 2023-09-23 19:38 UTC (permalink / raw)
  To: emacs-orgmode


Hi,
I am trying to understand how to set hours:minutes values in tables conditionally.

Just setting hours directly works:

| 40:03:00 |
| 40:03:00 |
| 40:03:00 |
#+TBLFM: $1=40:03;T

But when doing that conditionally (first row different from the others),
I do not understand the behavior:

This seemed to work:

| 19:55:00 |
| 40:03:00 |
| 40:03:00 |
#+TBLFM: $1=if(@# <= 1, 19:55, 40:03);T

But after adjusting the minutes, this happens:

| 19:55:00 |
| 00:00:40 |
| 00:00:40 |
#+TBLFM: $1=if(@# <= 1, 19:55, 40:01);T

What would be the correct way to do this?

PS: I have found that the same happens when I add parentheses:

| 40:03:00 |
| 40:03:00 |
| 40:03:00 |
#+TBLFM: $1=(40:03);T

| 00:00:40 |
| 00:00:40 |
| 00:00:40 |
#+TBLFM: $1=(40:01);T

PPS: I came across this when trying to understand the formulas here
https://github.com/clange/org-mode

Thanks
Chris


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calc/TBLFM: how to conditionally insert hours:minutes?
  2023-09-23 19:38 Calc/TBLFM: how to conditionally insert hours:minutes? Chris Keschnat
@ 2023-09-25  9:32 ` Bruno Barbier
  2023-09-25 17:36   ` Chris Keschnat
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Barbier @ 2023-09-25  9:32 UTC (permalink / raw)
  To: Chris Keschnat, emacs-orgmode


Hi Chris,

Chris Keschnat <chris@catsu.it> writes:

>
> | 19:55:00 |
> | 00:00:40 |
> | 00:00:40 |
> #+TBLFM: $1=if(@# <= 1, 19:55, 40:01);T
>
> What would be the correct way to do this?
>

It seems that org tries to convert times back and forth when evaluating
formulas; but, in your case, it cannot convert them because it doesn't
spot them inside your formula.

You could switch to the "Lisp" syntax (as opposed to the "Calc" syntax),
and, write the conversion manually:

    | 19:55:00 |
    | 40:01:00 |
    | 40:01:00 |
    #+TBLFM: $1='(org-table-time-string-to-seconds (if (<= @# 1) "19:55" "40:01"));T

Note that, for Calc, 'X:Y' means the fraction 'X/Y' of the two
integers X and Y:

   40:01 = 40/1 = 40
   40:02 = 40/2 = 20
   40:03 = 40/3
   40:04 = 40/4 = 10


Bruno







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calc/TBLFM: how to conditionally insert hours:minutes?
  2023-09-25  9:32 ` Bruno Barbier
@ 2023-09-25 17:36   ` Chris Keschnat
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Keschnat @ 2023-09-25 17:36 UTC (permalink / raw)
  To: emacs-orgmode


Hi Bruno,

> You could switch to the "Lisp" syntax (as opposed to the "Calc" syntax),
> and, write the conversion manually:
>
>     | 19:55:00 |
>     | 40:01:00 |
>     | 40:01:00 |
>
>     #+TBLFM: $1='(org-table-time-string-to-seconds (if (<= @# 1) "19:55" "40:01"));T

awesome, thank out. This works as expected with the little addendum that
@# in Calc seems to ignore the header line (not present in this
example), but the Lispy syntax doesn't. So the 1 in the "if" becomes a 2.

> Note that, for Calc, 'X:Y' means the fraction 'X/Y' of the two
> integers X and Y:
>
>    40:01 = 40/1 = 40
>    40:02 = 40/2 = 20
>    40:03 = 40/3
>    40:04 = 40/4 = 10

This also explains why 40:00 errors out :)

Thanks a lot

Chris


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-25 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-23 19:38 Calc/TBLFM: how to conditionally insert hours:minutes? Chris Keschnat
2023-09-25  9:32 ` Bruno Barbier
2023-09-25 17:36   ` Chris Keschnat

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).