emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Does Effort support hours only?
@ 2011-02-17 19:47 Luke Crook
  2011-02-18  9:02 ` Bastien
  2011-02-28 11:43 ` [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?) Lawrence Mitchell
  0 siblings, 2 replies; 9+ messages in thread
From: Luke Crook @ 2011-02-17 19:47 UTC (permalink / raw)
  To: emacs-orgmode

Is it possible to specify estimated effort in something other 
than hours (0.5, or 0:30)?

For example 1w, 1m, 2d etc?

-Luke

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

* Re: Does Effort support hours only?
  2011-02-17 19:47 Does Effort support hours only? Luke Crook
@ 2011-02-18  9:02 ` Bastien
  2011-02-18  9:48   ` Sébastien Vauban
  2011-02-28 11:43 ` [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?) Lawrence Mitchell
  1 sibling, 1 reply; 9+ messages in thread
From: Bastien @ 2011-02-18  9:02 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode

Hi Luke,

Luke Crook <luke@balooga.com> 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.

-- 
 Bastien

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

* Re: Does Effort support hours only?
  2011-02-18  9:02 ` Bastien
@ 2011-02-18  9:48   ` Sébastien Vauban
  2011-02-18 10:51     ` Lawrence Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Sébastien Vauban @ 2011-02-18  9:48 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bastien and Luke,

Bastien wrote:
> Luke Crook <luke-bul7fGZb+kRBDgjK7y7TUQ@public.gmane.org> 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.

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Does Effort support hours only?
  2011-02-18  9:48   ` Sébastien Vauban
@ 2011-02-18 10:51     ` Lawrence Mitchell
  2011-02-18 22:40       ` Herbert Sitz
  0 siblings, 1 reply; 9+ messages in thread
From: Lawrence Mitchell @ 2011-02-18 10:51 UTC (permalink / raw)
  To: emacs-orgmode

Sébastien Vauban wrote:
> Hi Bastien and Luke,

> Bastien wrote:
>> Luke Crook <luke@balooga.com> 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 <wence@gmx.li>

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

* Re: Does Effort support hours only?
  2011-02-18 10:51     ` Lawrence Mitchell
@ 2011-02-18 22:40       ` Herbert Sitz
  2011-02-21  9:47         ` Lawrence Mitchell
  0 siblings, 1 reply; 9+ messages in thread
From: Herbert Sitz @ 2011-02-18 22:40 UTC (permalink / raw)
  To: emacs-orgmode

Lawrence Mitchell <wence <at> gmx.li> writes:
> >>> Is it possible to specify estimated effort in something other than hours
> >>> (0.5, or 0:30)?
> 
> > 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.
> 

Lawrence -- 

I didn't test the patch, but it looks like it's hard coded to treat 24 hours as
1 day, 168 hours as 1 week, etc.  This seems like it would create more confusion
than there was before.  

In the context of measuring effort I think it's far more common to treat, e.g, 8
hours as the equivalent of a day's work.  Most people have 5 day works weeks,
but some don't. Etc.  In any case, giving user ability to set their own
conversion factors seems like a much-needed part of this.

-- Herb

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

* Re: Does Effort support hours only?
  2011-02-18 22:40       ` Herbert Sitz
@ 2011-02-21  9:47         ` Lawrence Mitchell
  0 siblings, 0 replies; 9+ messages in thread
From: Lawrence Mitchell @ 2011-02-21  9:47 UTC (permalink / raw)
  To: emacs-orgmode

Herbert Sitz wrote:
> Lawrence Mitchell <wence <at> gmx.li> writes:
>>>>> Is it possible to specify estimated effort in something other than hours
>>>>> (0.5, or 0:30)?

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


> Lawrence --

> I didn't test the patch, but it looks like it's hard coded to
> treat 24 hours as 1 day, 168 hours as 1 week, etc.  This seems
> like it would create more confusion than there was before.

> In the context of measuring effort I think it's far more common
> to treat, e.g, 8 hours as the equivalent of a day's work.  Most
> people have 5 day works weeks, but some don't. Etc.  In any
> case, giving user ability to set their own conversion factors
> seems like a much-needed part of this.

That is true.  The hard-coded values were just as an example.  It
would be reasonably trivial to introduce a variable that encoded
the number of hours a day's effort would contain.  The patch was
just an example that the changes would not be too sweeping.  In
fact, here's a patch on top that would allow user-customization:

diff --git a/lisp/org.el b/lisp/org.el
index 2027809..c3373fa 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15473,27 +15473,41 @@ If no number is found, the return value is 0."
     (string-to-number (match-string 1 s)))
    (t 0)))
 
+(defcustom org-effort-durations
+  `(("h" . 60)
+    ("d" . ,(* 60 8))
+    ("w" . ,(* 60 8 5))
+    ("m" . ,(* 60 8 5 4))
+    ("y" . ,(* 60 8 5 40)))
+  "Conversion factor to minutes for an effort modifier.
+
+Each entry has the form (MODIFIER . MINUTES).
+
+In an effort string, a number followed by MODIFIER is multiplied
+by the specified number of MINUTES to obtain an effort in
+minutes.
+
+For example, if the value of this variable is ((\"hours\" . 60)), then an
+effort string \"2hours\" is equivalent to 120 minutes."
+  :group 'org-agenda
+  :type '(alist :key-type (string :tag "Modifier")
+		:value-type (number :tag "Minutes")))
+
 (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)
+A bare number is interpreted as minutes, modifiers can be set by
+customizing `org-effort-durations' (which see).
 
 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))
+  (let ((result 0)
+	(regex (rx (group (1+ (any "0-9")))
+		   (0+ (syntax whitespace))
+		   (group
+		    (eval (cons 'or (mapcar 'car org-effort-durations)))))))
+    (while (string-match regex s)
+      (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
 		      (string-to-number (match-string 1 s))))
       (setq s (replace-match "" nil t s)))
     (incf result (org-hh:mm-string-to-minutes s))

-- 
Lawrence Mitchell <wence@gmx.li>

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

* [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?)
  2011-02-17 19:47 Does Effort support hours only? Luke Crook
  2011-02-18  9:02 ` Bastien
@ 2011-02-28 11:43 ` Lawrence Mitchell
  2011-03-06 17:45   ` [Accepted] [O] " Bastien Guerry
  2011-03-06 17:47   ` [PATCH] Support modifiers in effort durations Bastien
  1 sibling, 2 replies; 9+ messages in thread
From: Lawrence Mitchell @ 2011-02-28 11:43 UTC (permalink / raw)
  To: Luke Crook; +Cc: emacs-orgmode, Sébastien Vauban

Luke Crook wrote:
> Is it possible to specify estimated effort in something other
> than hours (0.5, or 0:30)?

> For example 1w, 1m, 2d etc?

Here's a cleaned up patch that allows user-specified modifiers
for effort strings.  The new variable `org-effort-durations'
lists modifiers, and their mapping to minutes (words, as well as
single-letter modifiers, are supported).  The default value is:

(("h" . 60)
 ("d" . 480) ; 8 hours
 ("w" . 2400) ; five days
 ("m" . 9600) ; 4 weeks
 ("y" . 96000)) ; 40 weeks

But you can change this.

Old effort strings (HH:MM) are still interpreted correctly.  See
the docstrings of `org-effort-durations' and
`org-duration-string-to-minutes' for more details.

From a0e24b14755eb4087d9c47bb4eea11eb9151efcf Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <wence@gmx.li>
Date: Fri, 18 Feb 2011 11:01:46 +0000
Subject: [PATCH] Allow human-readable effort durations
To: emacs-orgmode@gnu.org

* lisp/org.el (org-effort-durations): New variable.
* lisp/org.el (org-duration-string-to-minutes): New function.
* lisp/org-agenda.el (org-agenda-filter-effort-form)
(org-format-agenda-item): Use it.
* lisp/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-modify-effort-estimate, org-clock-get-clock-string): Use it.

Specifying large effort durations in hours and minutes is difficult.
Is 130:25 more than two weeks effort?  More than three?  This patch
allows specification of an effort duration as a friendly string.  For
example 2w 5d is two weeks and five days of effort.  Existing H:MM
entries will still be recognised correctly.
---
 lisp/org-agenda.el |    4 ++--
 lisp/org-clock.el  |    8 ++++----
 lisp/org.el        |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index dee23e0..87602dc 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5334,7 +5334,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
@@ -6061,7 +6061,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 6b45ca5..cc11f3c 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -487,7 +487,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
@@ -561,10 +561,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)))))
@@ -581,7 +581,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 03f0b72..9cf1c94 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15499,6 +15499,47 @@ If no number is found, the return value is 0."
     (string-to-number (match-string 1 s)))
    (t 0)))
 
+(defcustom org-effort-durations
+  `(("h" . 60)
+    ("d" . ,(* 60 8))
+    ("w" . ,(* 60 8 5))
+    ("m" . ,(* 60 8 5 4))
+    ("y" . ,(* 60 8 5 40)))
+  "Conversion factor to minutes for an effort modifier.
+
+Each entry has the form (MODIFIER . MINUTES).
+
+In an effort string, a number followed by MODIFIER is multiplied
+by the specified number of MINUTES to obtain an effort in
+minutes.
+
+For example, if the value of this variable is ((\"hours\" . 60)), then an
+effort string \"2hours\" is equivalent to 120 minutes."
+  :group 'org-agenda
+  :type '(alist :key-type (string :tag "Modifier")
+		:value-type (number :tag "Minutes")))
+
+(defun org-duration-string-to-minutes (s)
+  "Convert a duration string S to minutes.
+
+A bare number is interpreted as minutes, modifiers can be set by
+customizing `org-effort-durations' (which see).
+
+Entries containing a colon are interpreted as H:MM by
+`org-hh:mm-string-to-minutes'."
+  (let ((result 0)
+	(regex (rx-to-string (group (1+ (any "0-9")))
+			     (0+ (syntax whitespace))
+			     (group
+			      (eval (cons 'or
+					  (mapcar 'car org-effort-durations)))))))
+    (while (string-match regex s)
+      (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
+		      (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 ()
-- 
1.7.4.rc2.18.gb20e9

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

* [Accepted] [O] Support modifiers in effort durations (was: Re: Does Effort support hours only?)
  2011-02-28 11:43 ` [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?) Lawrence Mitchell
@ 2011-03-06 17:45   ` Bastien Guerry
  2011-03-06 17:47   ` [PATCH] Support modifiers in effort durations Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien Guerry @ 2011-03-06 17:45 UTC (permalink / raw)
  To: emacs-orgmode

Patch 638 (http://patchwork.newartisans.com/patch/638/) is now "Accepted".

Maintainer comment: none

This relates to the following submission:

http://mid.gmane.org/%3Cm3tyfo1j16.fsf%40e4300lm.epcc.ed.ac.uk%3E

Here is the original message containing the patch:

> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [O] Support modifiers in effort durations (was: Re: Does Effort
> 	support hours only?)
> Date: Mon, 28 Feb 2011 16:43:33 -0000
> From: Lawrence Mitchell <wence@gmx.li>
> X-Patchwork-Id: 638
> Message-Id: <m3tyfo1j16.fsf@e4300lm.epcc.ed.ac.uk>
> To: Luke Crook <luke@balooga.com>
> Cc: emacs-orgmode@gnu.org, =?utf-8?Q?S=C3=A9bastien?= Vauban
> 	<wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
> 
> Luke Crook wrote:
> > Is it possible to specify estimated effort in something other
> > than hours (0.5, or 0:30)?
> 
> > For example 1w, 1m, 2d etc?
> 
> Here's a cleaned up patch that allows user-specified modifiers
> for effort strings.  The new variable `org-effort-durations'
> lists modifiers, and their mapping to minutes (words, as well as
> single-letter modifiers, are supported).  The default value is:
> 
> (("h" . 60)
>  ("d" . 480) ; 8 hours
>  ("w" . 2400) ; five days
>  ("m" . 9600) ; 4 weeks
>  ("y" . 96000)) ; 40 weeks
> 
> But you can change this.
> 
> Old effort strings (HH:MM) are still interpreted correctly.  See
> the docstrings of `org-effort-durations' and
> `org-duration-string-to-minutes' for more details.
> 
> >From a0e24b14755eb4087d9c47bb4eea11eb9151efcf Mon Sep 17 00:00:00 2001
> From: Lawrence Mitchell <wence@gmx.li>
> Date: Fri, 18 Feb 2011 11:01:46 +0000
> Subject: [PATCH] Allow human-readable effort durations
> To: emacs-orgmode@gnu.org
> 
> * lisp/org.el (org-effort-durations): New variable.
> * lisp/org.el (org-duration-string-to-minutes): New function.
> * lisp/org-agenda.el (org-agenda-filter-effort-form)
> (org-format-agenda-item): Use it.
> * lisp/org-clock.el (org-clock-notify-once-if-expired)
> (org-clock-modify-effort-estimate, org-clock-get-clock-string): Use it.
> 
> Specifying large effort durations in hours and minutes is difficult.
> Is 130:25 more than two weeks effort?  More than three?  This patch
> allows specification of an effort duration as a friendly string.  For
> example 2w 5d is two weeks and five days of effort.  Existing H:MM
> entries will still be recognised correctly.
> 
> ---
> lisp/org-agenda.el |    4 ++--
>  lisp/org-clock.el  |    8 ++++----
>  lisp/org.el        |   41 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 47 insertions(+), 6 deletions(-)
> 
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index dee23e0..87602dc 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -5334,7 +5334,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
> @@ -6061,7 +6061,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 6b45ca5..cc11f3c 100644
> --- a/lisp/org-clock.el
> +++ b/lisp/org-clock.el
> @@ -487,7 +487,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
> @@ -561,10 +561,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)))))
> @@ -581,7 +581,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 03f0b72..9cf1c94 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -15499,6 +15499,47 @@ If no number is found, the return value is 0."
>      (string-to-number (match-string 1 s)))
>     (t 0)))
>  
> +(defcustom org-effort-durations
> +  `(("h" . 60)
> +    ("d" . ,(* 60 8))
> +    ("w" . ,(* 60 8 5))
> +    ("m" . ,(* 60 8 5 4))
> +    ("y" . ,(* 60 8 5 40)))
> +  "Conversion factor to minutes for an effort modifier.
> +
> +Each entry has the form (MODIFIER . MINUTES).
> +
> +In an effort string, a number followed by MODIFIER is multiplied
> +by the specified number of MINUTES to obtain an effort in
> +minutes.
> +
> +For example, if the value of this variable is ((\"hours\" . 60)), then an
> +effort string \"2hours\" is equivalent to 120 minutes."
> +  :group 'org-agenda
> +  :type '(alist :key-type (string :tag "Modifier")
> +		:value-type (number :tag "Minutes")))
> +
> +(defun org-duration-string-to-minutes (s)
> +  "Convert a duration string S to minutes.
> +
> +A bare number is interpreted as minutes, modifiers can be set by
> +customizing `org-effort-durations' (which see).
> +
> +Entries containing a colon are interpreted as H:MM by
> +`org-hh:mm-string-to-minutes'."
> +  (let ((result 0)
> +	(regex (rx-to-string (group (1+ (any "0-9")))
> +			     (0+ (syntax whitespace))
> +			     (group
> +			      (eval (cons 'or
> +					  (mapcar 'car org-effort-durations)))))))
> +    (while (string-match regex s)
> +      (incf result (* (cdr (assoc (match-string 2 s) org-effort-durations))
> +		      (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 ()
> 

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

* Re: [PATCH] Support modifiers in effort durations
  2011-02-28 11:43 ` [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?) Lawrence Mitchell
  2011-03-06 17:45   ` [Accepted] [O] " Bastien Guerry
@ 2011-03-06 17:47   ` Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2011-03-06 17:47 UTC (permalink / raw)
  To: Lawrence Mitchell; +Cc: emacs-orgmode, Sébastien Vauban, Luke Crook

Hi Lawrence,

Lawrence Mitchell <wence@gmx.li> writes:

> Here's a cleaned up patch that allows user-specified modifiers
> for effort strings.  The new variable `org-effort-durations'
> lists modifiers, and their mapping to minutes (words, as well as
> single-letter modifiers, are supported).  

Thanks a lot for this patch -- I've now applied it.  I've just changed
the way the regular expression is computed, I find rx-to-string a bit
confusing (surely a matter of taste).

> The default value is:
>
> (("h" . 60)
>  ("d" . 480) ; 8 hours
>  ("w" . 2400) ; five days
>  ("m" . 9600) ; 4 weeks
>  ("y" . 96000)) ; 40 weeks

I agree this make sense.

Thanks again,

-- 
 Bastien

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

end of thread, other threads:[~2011-03-06 17:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-17 19:47 Does Effort support hours only? Luke Crook
2011-02-18  9:02 ` Bastien
2011-02-18  9:48   ` Sébastien Vauban
2011-02-18 10:51     ` Lawrence Mitchell
2011-02-18 22:40       ` Herbert Sitz
2011-02-21  9:47         ` Lawrence Mitchell
2011-02-28 11:43 ` [PATCH] Support modifiers in effort durations (was: Re: Does Effort support hours only?) Lawrence Mitchell
2011-03-06 17:45   ` [Accepted] [O] " Bastien Guerry
2011-03-06 17:47   ` [PATCH] Support modifiers in effort durations Bastien

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