From: Carsten Dominik <carsten.dominik@gmail.com>
To: Nick <oinksocket@letterboxes.org>
Cc: emacs-orgmode@gnu.org
Subject: Re: spreadsheet table limitations, specifically summing hours?
Date: Sat, 15 May 2010 08:31:36 +0200 [thread overview]
Message-ID: <B2C9004B-7EBD-447D-B28A-1EA9D9135CD6@gmail.com> (raw)
In-Reply-To: <4BED62FD.1010502@letterboxes.org>
Hi Nick, these are useful functions, thanks! Maybe add the to org-
hacks?
Also, I could think of generalizations:
Allow 94h and 94:16h and 94:16:22h.
I would, in fact, strip the "h" and just use 94:16
- Carsten
On May 14, 2010, at 4:49 PM, Nick wrote:
> Earlier I wrote:
>> There seem to be two problems;
>>
>> c) Summing HH:MM values (which org-table-sum seems to manage -
>> although oddly
>> without including the minutes - but not vsum)
>
> Excuse me answering my own question, but time is money, and so I've
> hastily
> written my own elisp functions to do this (appended). Perhaps this
> will help
> someone else.
>
> Given these functions defined in a .emacs config or similar, I can do:
>
>
>
>
> | | week ending | hh:mm | Total H | Total | VAT | Total+VAT |
> | ! | week | hhmm | hours | total | vat | |
> |---+-------------+--------+---------+-------+--------+-----------|
> | | 28/02/10 | 20:11h | | | | |
> | | 07/03/10 | 21:11h | | | | |
> | | 14/03/10 | 25:40h | | | | |
> | | 21/03/10 | 27:16h | | | | |
> |---+-------------+--------+---------+-------+--------+-----------|
> | # | 22/03/10 | 94:18h | 94 | 2820 | 493.50 | 3313.50 |
> |---+-------------+--------+---------+-------+--------+-----------|
> | | 28/03/10 | 26:24h | | | | |
> | | 04/04/10 | 21:15h | | | | |
> | | 11/04/10 | 23:15h | | | | |
> |---+-------------+--------+---------+-------+--------+-----------|
> | # | 27/02/10 | 70:54h | 71 | 2130 | 372.75 | 2502.75 |
> |---+-------------+--------+---------+-------+--------+-----------|
> #+TBLFM: $3='(reduce 'my-sum-hhmm '(@-I..@-II))::$4='(round (my-hhmm-
> to-hours
> $hhmm))::$5=$hours*$hourlyrate::$6=$total*$vatrate;%.2f::$7=$total+
> $vat;%.2f
> #+CONSTANTS: vatrate=0.175 hourlyrate=35
>
>
> Although I'd still be interested if someone can show me a better way.
>
> Cheers,
>
> N
>
> ps I wonder if a long set of formulae like this could be split over
> several
> +TBLFM lines? The answer seems to be no.
>
> ----
> ;; Parse an HH::MM date into a list containing a pair of numbers,
> (HH MM)
> (defun my-parse-hhmm (hhmm)
> (let ((date-re "\\([0-9]+\\):\\([0-9]+\\)h?")
> hours
> minutes)
> (unless (string-match date-re hhmm)
> (error "Argument is not a valid date: '%s'" hhmm))
> (setq hours (string-to-number (match-string 1 hhmm))
> minutes (string-to-number (match-string 2 hhmm)))
> (list hours minutes)))
>
> ;; Convert a HH:MM date to a (possibly fractional) number of hours
> (defun my-hhmm-to-hours (hhmm)
> (let* ((date (my-parse-hhmm hhmm))
> (hours (first date))
> (minutes (second date)))
> (+ (float hours) (/ (float minutes) 60.0))))
>
>
> ;; Date summing
> ;; This can be used in a table formula like this:
> ;; #+TBLFM: $3='(reduce 'my-sum-dates '(@-I..@-II))
> (defun my-sum-hhmm (a b)
> (let* (;; parse a
> (a-date (my-parse-hhmm a))
> (a-hours (first a-date))
> (a-minutes (second a-date))
>
> ;; parse b
> (b-date (my-parse-hhmm b))
> (b-hours (first b-date))
> (b-minutes (second b-date))
>
> ;; add the parts together
> (minutes (+ a-minutes b-minutes))
> (hours (+ a-hours b-hours))
> (carry (floor (/ minutes 60)))
> (remainder (mod minutes 60)))
> (format "%d:%02dh" (+ hours carry) remainder)))
>
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
- Carsten
next prev parent reply other threads:[~2010-05-15 6:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-14 10:27 spreadsheet table limitations, specifically summing hours? Nick
2010-05-14 14:44 ` Nick Stokoe
2010-05-15 14:27 ` Carsten Dominik
2010-05-14 14:49 ` Nick
2010-05-14 21:59 ` Stephan Schmitt
2010-05-14 23:40 ` Nick
2010-05-15 6:24 ` Carsten Dominik
2010-05-15 6:31 ` Carsten Dominik [this message]
2010-05-17 13:34 ` oinksocket
2010-05-17 19:29 ` Štěpán Němec
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=B2C9004B-7EBD-447D-B28A-1EA9D9135CD6@gmail.com \
--to=carsten.dominik@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=oinksocket@letterboxes.org \
/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).