emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* question and use example
@ 2009-08-26 16:38 Paul Menair
  2009-08-26 20:18 ` Benjamin Andresen
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Menair @ 2009-08-26 16:38 UTC (permalink / raw)
  To: emacs-orgmode

Folks,

I've been struggling with something and thought I'd ask you folks.

I'm an attorney.  I use org-mode for various things, because it's convenient, simple and flexible.  And most case management software for lawyers is awful.  Anyway, one of the things I do in org is keep my time.  

The ordinary timekeeping function in org is interesting and neat in some ways, but not useful for my purposes.  I need to provide my employer with a set of timeslips, where each record consists of a date, client name, description, and time interval in decimal form.  Everything that I've tried that attempts to "help" me do this fails in one way or another.  The solution I have is a table in org that is set up like this:

| date | client | desc | [time]--[time] | H:M | x.x |

Org is perfect for this because it does what no other time and billing solution I've seen does -- it lets me just record two timestamps in plain text and get an interval.  The only other piece of software I've ever seen that does this was a calendar program that let you do this in its notes field.

My problem is this.  I populate the fifth field with c-- c-u c-y.  I would be nice if it happened automatically, but that's no big deal.  However, I've been going through and manually entering the sixth field, and that does end up being a hassle.

Calc seems to only work on timestamps and not have any straight way to convert H:M to decimal.  I suppose I could keep my in and out timestamps in separate fields and figure out a way to have calc work on them, but it seems like there should be an easier solution.

Any thoughts?  In any event, I thought it might be of interest for folks to see a use case from a non-engineering professional.

Paul

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

* Re: question and use example
  2009-08-26 16:38 question and use example Paul Menair
@ 2009-08-26 20:18 ` Benjamin Andresen
  2009-08-26 22:32   ` Nick Dokos
  0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Andresen @ 2009-08-26 20:18 UTC (permalink / raw)
  To: emacs-orgmode

Hey Paul,

Paul Menair <pmenair@gmail.com> writes:

> My problem is this.  I populate the fifth field with c-- c-u c-y.  I
> would be nice if it happened automatically, but that's no big deal.
> However, I've been going through and manually entering the sixth
> field, and that does end up being a hassle.

I whipped something up that should work for you.

You need to evaluate the code below and then the below table will work
for you.

(defun ba/org-timerange (s &optional in-min)
  (let* ((re "^\\(.*?\\)--\\(.*?\\)$")
         (start (replace-regexp-in-string re "\\1" s))
         (end (replace-regexp-in-string re "\\2" s))
         (start-in-min (org-hh:mm-string-to-minutes start))
         (end-in-min (org-hh:mm-string-to-minutes end))
         (diff-in-min (- end-in-min start-in-min)))
    (if in-min
        diff-in-min
        (format "%.2f" (/ diff-in-min (float 60))))))

| date             | client | desc  | timerange                                      |  H:M | in dec |
|------------------+--------+-------+------------------------------------------------+------+--------|
| <2009-08-26 Wed> | benny  | foo'd | <2009-08-26 Wed 21:55>--<2009-08-26 Wed 21:58> | 0:03 |   0.05 |
#+TBLFM: $5='(org-minutes-to-hh:mm-string (ba/org-timerange $4 t))::$6='(ba/org-timerange $4)

If you're on the table and you press C-u C-c C-c and it should put the
correct info at the respective places.

Now what I recommend is using autocalc instead so you don't have to
worry about doing this. This would require you to change your table to
the following format:

|   | date             | client | desc   | timerange                                      |  H:M | in dec |
|---+------------------+--------+--------+------------------------------------------------+------+--------|
| # | <2009-08-25 Tue> | benny  | foo'd  | <2009-08-25 Tue 20:55>--<2009-08-25 Tue 23:58> | 3:03 |   3.05 |
| # | <2009-08-26 Wed> | bar    | quux'd | <2009-08-26 Wed 22:10>--<2009-08-26 Wed 22:14> | 0:04 |   0.07 |
#+TBLFM: $6='(org-minutes-to-hh:mm-string (ba/org-timerange $5 t))::$7='(ba/org-timerange $5)

The "#" in the first column achieves this. See (info "(org)Advanced features")
for more information.

> Paul

HTH,
benny

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

* Re: Re: question and use example
  2009-08-26 20:18 ` Benjamin Andresen
@ 2009-08-26 22:32   ` Nick Dokos
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Dokos @ 2009-08-26 22:32 UTC (permalink / raw)
  To: Benjamin Andresen; +Cc: emacs-orgmode

Benjamin Andresen <bandresen@gmail.com> wrote:

> Hey Paul,
> 
> Paul Menair <pmenair@gmail.com> writes:
> 
> > My problem is this.  I populate the fifth field with c-- c-u c-y.  I
> > would be nice if it happened automatically, but that's no big deal.
> > However, I've been going through and manually entering the sixth
> > field, and that does end up being a hassle.
> 
> I whipped something up that should work for you.
> 

Very nice!

There is a simpler approach, but with the disadvantage that
it requires modifications to the structure of the table (iow, I don't
know how to do it with a time range :-) The main simplification is that
it uses built-in functions.

The table looks like this:

|   | date             | client | desc  | start time             | end time               | duration in dec |  H:M |
|---+------------------+--------+-------+------------------------+------------------------+-----------------+------|
| # | <2009-08-26 Wed> | benny  | foo'd | <2009-08-26 Wed 14:45> | <2009-08-26 Wed 18:05> |            3.33 | 3:20 |

#+TBLFM: $7=(date(<$6>) - date(<$5>))*24;%.2f :: $8='(org-minutes-to-hh:mm-string (round (* $7 60)));N

Note that the primary result is the time interval in decimal hours - the
hh:mm result is derived from that. Note also that the rounding is necessary
because org-minutes-to-hh:mm-string assumes that its argument is an integer
and misbehaves if it is not:

(org-minutes-to-hh:mm-string 73.2) --> "1:00"
(org-minutes-to-hh:mm-string 73) --> "1:13"

I'm sure there are other approaches as well - investigating the built-in
clocking and attendant reports is probably a good idea as well. Bernt
Hansen has some information in his org-mode page[1], and there is a
tutorial about it on worg[2].

HTH,
Nick

[1] http://doc.norang.ca/org-mode.html
[2] http://orgmode.org/worg/org-tutorials/index.php - the tutorial itself
    is at http://sachachua.com/wp/2007/12/30/clocking-time-with-emacs-org/,
    but note that it's 1.5 years old and I don't know whether it's still
    useful or whether it's completely out of date by this time.
    

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

end of thread, other threads:[~2009-08-26 22:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-26 16:38 question and use example Paul Menair
2009-08-26 20:18 ` Benjamin Andresen
2009-08-26 22:32   ` Nick Dokos

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