From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lawrence Mitchell Subject: Re: Does Effort support hours only? Date: Fri, 18 Feb 2011 10:51:58 +0000 Message-ID: References: <87sjvlg1h1.fsf@gnu.org> <80pqqp4qss.fsf@missioncriticalit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from [140.186.70.92] (port=51028 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PqNwc-0001bc-1j for emacs-orgmode@gnu.org; Fri, 18 Feb 2011 05:52:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PqNwa-0002x1-J3 for emacs-orgmode@gnu.org; Fri, 18 Feb 2011 05:52:13 -0500 Received: from lo.gmane.org ([80.91.229.12]:57588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PqNwa-0002wi-5H for emacs-orgmode@gnu.org; Fri, 18 Feb 2011 05:52:12 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PqNwY-0004rV-2F for emacs-orgmode@gnu.org; Fri, 18 Feb 2011 11:52:10 +0100 Received: from e4300lm.epcc.ed.ac.uk ([129.215.63.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Feb 2011 11:52:10 +0100 Received: from wence by e4300lm.epcc.ed.ac.uk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 18 Feb 2011 11:52:10 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Sébastien Vauban wrote: > Hi Bastien and Luke, > Bastien wrote: >> Luke Crook writes: >>> Is it possible to specify estimated effort in something other than hours >>> (0.5, or 0:30)? >> No, it's not possible right now. > But I second this idea: that'd be a great addition. Too often, we have to play > with figures such as 64:00 or 80:00 just to indicate 8 or 10 days... > Being able to specify suffixes like `d' for days or `w' for weeks would be > awesome. But I guess it's very, very complex, though. Turns out probably not, unless I've missed something. I think this set of patches does what's necessary to allow duration strings in effort properties. And as a bonus its backwards compatible to the old style. Try it and see if it works, if it does I'll roll it into a proper patch. diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index 54de775..6634801 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -5319,7 +5319,7 @@ Any match of REMOVE-RE will be removed from TXT." (get-text-property 0 'org-marker txt))) (error nil))) (when effort - (setq neffort (org-hh:mm-string-to-minutes effort) + (setq neffort (org-duration-string-to-minutes effort) effort (setq effort (concat "[" effort "]" ))))) (when remove-re @@ -6046,7 +6046,7 @@ E looks like \"+<2:25\"." ((equal op ??) op) (t '=))) (list 'org-agenda-compare-effort (list 'quote op) - (org-hh:mm-string-to-minutes e)))) + (org-duration-string-to-minutes e)))) (defun org-agenda-compare-effort (op value) "Compare the effort of the current line with VALUE, using OP. diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 07cc952..0747210 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -486,7 +486,7 @@ If not, show simply the clocked time like 01:50." (m (- clocked-time (* 60 h)))) (if org-clock-effort (let* ((effort-in-minutes - (org-hh:mm-string-to-minutes org-clock-effort)) + (org-duration-string-to-minutes org-clock-effort)) (effort-h (floor effort-in-minutes 60)) (effort-m (- effort-in-minutes (* effort-h 60))) (work-done-str @@ -560,10 +560,10 @@ the mode line." ;; A string. See if it is a delta (setq sign (string-to-char value)) (if (member sign '(?- ?+)) - (setq current (org-hh:mm-string-to-minutes current) + (setq current (org-duration-string-to-minutes current) value (substring value 1)) (setq current 0)) - (setq value (org-hh:mm-string-to-minutes value)) + (setq value (org-duration-string-to-minutes value)) (if (equal ?- sign) (setq value (- current value)) (if (equal ?+ sign) (setq value (+ current value))))) @@ -580,7 +580,7 @@ the mode line." "Show notification if we spent more time than we estimated before. Notification is shown only once." (when (org-clocking-p) - (let ((effort-in-minutes (org-hh:mm-string-to-minutes org-clock-effort)) + (let ((effort-in-minutes (org-duration-string-to-minutes org-clock-effort)) (clocked-time (org-clock-get-clocked-time))) (if (setq org-task-overrun (if (or (null effort-in-minutes) (zerop effort-in-minutes)) diff --git a/lisp/org.el b/lisp/org.el index 82a0986..3e8fbba 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15446,6 +15446,32 @@ If no number is found, the return value is 0." (string-to-number (match-string 1 s))) (t 0))) +(defun org-duration-string-to-minutes (s) + "Convert a duration string S to minutes. + +A bare number is interpreted as minutes, the following suffixes are +recognised: + h - hours + d - days + w - weeks (7 days) + m - months (30 days) + y - years (365 days) + +Entries containing a colon are interpreted as H:MM by +`org-hh:mm-string-to-minutes'." + (let ((conversion `(("h" . 60) + ("d" . ,(* 60 24)) + ("w" . ,(* 60 24 7)) + ("m" . ,(* 60 24 7 30)) + ("y" . ,(* 60 24 7 365)))) + (result 0)) + (while (string-match "\\([0-9]+\\)\\([hdwmy]\\)" s) + (incf result (* (cdr (assoc (match-string 2 s) conversion)) + (string-to-number (match-string 1 s)))) + (setq s (replace-match "" nil t s))) + (incf result (org-hh:mm-string-to-minutes s)) + result)) + ;;;; Files (defun org-save-all-org-buffers () -- Lawrence Mitchell