From: Christian Moe <mail@christianmoe.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: Bastien <bzg@altern.org>,
emacs-orgmode@gnu.org, Martin Halder <martin.halder@gmail.com>
Subject: Re: org table calc and lisp for hh:mm timetable
Date: Tue, 22 Mar 2011 10:36:11 +0100 [thread overview]
Message-ID: <4D886D8B.10401@christianmoe.com> (raw)
In-Reply-To: <87mxknhioh.fsf@gmail.com>
Hi,
If we're not just looking for a neat workaround for some special cases
anymore, but looking at making org-tables aware of time-like strings
by default, a better strategy than to convert them into integers might
be to translate them into Calc time format and back again.
After all, Calc and hence the Org spreadsheet already handles time
arithmetic perfectly well, it's just that it would be nice to have
this functionality with the extra option to enter and display times as
=12:45= rather than =12@ 45'= or =12h 45m=.
(Personally, I can live with a =12h 45m= format, which is already a
Calc option: info:calc#HMS%20Forms, info:calc#HMS%20Formats.)
Consider this:
| Departure | Travel time | Arrival |
|------------------------+-------------+------------------------|
| [2011-03-22 Tue 23:15] | 7@ 05' | <2011-03-23 Wed 06:20> |
#+TBLFM: $3=<$1>+$2
With Calc, you can add a HMS time to a date-time and get the resulting
date-time. However, Calc apparently interprets integers as days, not
minutes or seconds. So if you convert 7:05 to an integer (425) and add
it to a date-time, you get a date about one year and two months ahead.
(Converting 7:05 to the integer 0.295139 days would work... but with
rounding problems.)
The Org spreadsheet already allows us to give the date-time as an
Org-style timestamp rather than in the Calc date format by using the
angle brackets in the formula. The solution would be similar option
for time-like strings, so we could write the travel time above as
=7:05=, and so the result below would be returned as =7:05=.
| Arrival | Departure | Travel time |
|------------------------+------------------------+-------------|
| <2011-03-23 Wed 06:20> | [2011-03-22 Tue 23:15] | 7@ 5' 0" |
#+TBLFM: $3=time(<$1>-<$2>)
Yours,
Christian
On 3/22/11 5:40 AM, Eric Schulte wrote:
>>
>> While this topic is raised, would it make sense for Org-mode table
>> formula to automatically parse any time-like string into time units
>> (i.e., base sixty). That would be the easiest for most users, and (I
>> imagine) would rarely result in surprising and unexpected behavior.
>>
>
> So, I took a shot at folding this into org-table.el, the resulting patch
> is attached. I'm not sure if this sort of automatic interpretation of
> time-like strings into integers is a good idea, or if this is the best
> implementation (I'm not incredibly familiar with Org's table handling)
> but after a couple of simple tests the patch does seem to work. For
> example the following...
>
> | 2:30 | 2 | 75 |
> #+TBLFM: $3=$1/$2
>
> It may make sense to also include functionality for converting the
> result back into a time string, e.g.
>
> #+begin_src emacs-lisp
> (defun org-time-seconds-to-string (secs)
> "Convert a number of seconds to a time string."
> (cond ((>= secs 3600) (format-seconds "%h:%.2m:%.2s" secs))
> ((>= secs 60) (format-seconds "%m:%.2s" secs))
> (t (format-seconds "%s" secs))))
> #+end_src
>
> | 2:30 | 2 | 1:15 |
> #+TBLFM: $3='(org-time-seconds-to-string (/ (string-to-number $1) (string-to-number $2)))
>
> While the above is cumbersome, there may be a simpler syntax or
> convention -- e.g., whenever one of the inputs is a time string then the
> results are displayed as a time string. Not sure what the best option
> is here, but thought this patch may spur some good suggestions.
>
> Best -- Eric
>
next prev parent reply other threads:[~2011-03-22 9:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-15 18:32 org table calc and lisp for hh:mm timetable Martin Halder
2011-03-15 19:22 ` Eric S Fraga
2011-03-15 19:49 ` Martin Halder
2011-03-15 20:37 ` Eric S Fraga
2011-03-15 21:47 ` Christian Moe
2011-03-16 9:22 ` Martin Halder
2011-03-17 7:49 ` Bastien
2011-03-20 17:50 ` Eric Schulte
2011-03-20 19:57 ` Eric S Fraga
2011-03-20 17:50 ` Eric Schulte
2011-03-20 21:00 ` Christian Moe
2011-03-20 23:43 ` Eric Schulte
2011-03-22 4:40 ` Eric Schulte
2011-03-22 9:36 ` Christian Moe [this message]
2011-03-24 1:18 ` Eric Schulte
2011-03-24 18:35 ` Martin Halder
2011-03-22 10:52 ` Carsten Dominik
2011-07-02 11:38 ` Bastien
2011-03-16 9:28 ` Eric S Fraga
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=4D886D8B.10401@christianmoe.com \
--to=mail@christianmoe.com \
--cc=bzg@altern.org \
--cc=emacs-orgmode@gnu.org \
--cc=martin.halder@gmail.com \
--cc=schulte.eric@gmail.com \
/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).