emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH v3 part3 0/4] fixing org-clock-time%
@ 2015-12-27 15:13 Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place Jan Malakhovski
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jan Malakhovski @ 2015-12-27 15:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Jan Malakhovski

This is a org-clock-time% piece of "[PATCH v2 0/9] mail, clock and
calc changes" updated with Aaron Ecay's suggestions.

The thing here is that I pretty much rewrote those changes because
they didn't work well with `org-effort-durations' (which was the case
even before I started, but it became apparent after I fixed
`org-clock-time%' to actually work).

So, I ended up rewriting `org-effort-durations'-related code, which
then allowed me to fix clock reports properly.

A piece of documentation in org.texi shows the new prowess.

This is the last patch series for now, I'm unhappy with ob-calc piece
of "[PATCH v2 0/9] mail, clock and calc changes", I'll send it when
its better.

Cheers,
  Jan

Jan Malakhovski (4):
  org: move `org-duration-string-to-minutes' to a better place
  rename `org-duration-string-to-minutes' to
    `org-clocksum-string-to-minutes' everywhere
  simplify and document `org-effort-durations'-related code
  org-clock: make clock table respect `org-effort-durations'

 contrib/lisp/org-depend.el     |   2 +-
 contrib/lisp/ox-taskjuggler.el |   2 +-
 doc/org.texi                   |   6 ++
 lisp/org-agenda.el             |   6 +-
 lisp/org-clock.el              |  62 ++++++++-------
 lisp/org-colview.el            |   3 +-
 lisp/org.el                    | 166 ++++++++++++++++++++++++-----------------
 7 files changed, 147 insertions(+), 100 deletions(-)

-- 
2.6.4

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

* [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place
  2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
@ 2015-12-27 15:13 ` Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 2/4] rename `org-duration-string-to-minutes' to `org-clocksum-string-to-minutes' everywhere Jan Malakhovski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jan Malakhovski @ 2015-12-27 15:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Jan Malakhovski

---
 lisp/org.el | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 74d1c4c..f6c513e 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18303,6 +18303,26 @@ 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 &optional output-to-string)
+  "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)
+	(re (concat "\\([0-9.]+\\) *\\("
+		    (regexp-opt (mapcar 'car org-effort-durations))
+		    "\\)")))
+    (while (string-match re 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)))
+    (setq result (floor result))
+    (incf result (org-hh:mm-string-to-minutes s))
+    (if output-to-string (number-to-string result) result)))
+
 (defcustom org-image-actual-width t
   "Should we use the actual width of images when inlining them?
 
@@ -18361,26 +18381,6 @@ The value is a list, with zero or more of the symbols `effort', `appt',
   :package-version '(Org . "8.3")
   :group 'org-agenda)
 
-(defun org-duration-string-to-minutes (s &optional output-to-string)
-  "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)
-	(re (concat "\\([0-9.]+\\) *\\("
-		    (regexp-opt (mapcar 'car org-effort-durations))
-		    "\\)")))
-    (while (string-match re 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)))
-    (setq result (floor result))
-    (incf result (org-hh:mm-string-to-minutes s))
-    (if output-to-string (number-to-string result) result)))
-
 ;;;; Files
 
 (defun org-save-all-org-buffers ()
-- 
2.6.4

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

* [PATCH 2/4] rename `org-duration-string-to-minutes' to `org-clocksum-string-to-minutes' everywhere
  2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place Jan Malakhovski
@ 2015-12-27 15:13 ` Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 3/4] simplify and document `org-effort-durations'-related code Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 4/4] org-clock: make clock table respect `org-effort-durations' Jan Malakhovski
  3 siblings, 0 replies; 5+ messages in thread
From: Jan Malakhovski @ 2015-12-27 15:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Jan Malakhovski

* lisp/org-agenda.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org.el:
* contrib/lisp/org-depend.el:
* contrib/lisp/ox-taskjuggler.el: Rename (org-duration-string-to-minutes)
  to (org-clocksum-string-to-minutes).
---
 contrib/lisp/org-depend.el     |  2 +-
 contrib/lisp/ox-taskjuggler.el |  2 +-
 lisp/org-agenda.el             |  2 +-
 lisp/org-clock.el              | 10 +++++-----
 lisp/org-colview.el            |  2 +-
 lisp/org.el                    | 14 +++++++++-----
 6 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/contrib/lisp/org-depend.el b/contrib/lisp/org-depend.el
index 1cd4130..7b263bc 100644
--- a/contrib/lisp/org-depend.el
+++ b/contrib/lisp/org-depend.el
@@ -270,7 +270,7 @@ This does two different kinds of triggers:
 			    (effort (when (or effort-up effort-down)
 				      (let ((effort (get-text-property (point) 'org-effort)))
 					(when effort
-					  (org-duration-string-to-minutes effort))))))
+					  (org-clocksum-string-to-minutes effort))))))
 			(push (list (point) todo-kwd priority tags effort)
 			      items))
 		      (unless (org-goto-sibling)
diff --git a/contrib/lisp/ox-taskjuggler.el b/contrib/lisp/ox-taskjuggler.el
index 2bd47e6..b425b1b 100644
--- a/contrib/lisp/ox-taskjuggler.el
+++ b/contrib/lisp/ox-taskjuggler.el
@@ -861,7 +861,7 @@ a unique id will be associated to it."
      (and complete (format "  complete %s\n" complete))
      (and effort
           (format "  effort %s\n"
-                  (let* ((minutes (org-duration-string-to-minutes effort))
+                  (let* ((minutes (org-clocksum-string-to-minutes effort))
                          (hours (/ minutes 60.0)))
                     (format "%.1fh" hours))))
      (and priority (format "  priority %s\n" priority))
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index d91b64d..99ccedd 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -7661,7 +7661,7 @@ E looks like \"+<2:25\"."
 		   ((equal op ??) op)
 		   (t '=)))
     (list 'org-agenda-compare-effort (list 'quote op)
-	  (org-duration-string-to-minutes e))))
+	  (org-clocksum-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 823a386..b7a70dc 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -663,7 +663,7 @@ If not, show simply the clocked time like 01:50."
   (let ((clocked-time (org-clock-get-clocked-time)))
     (if org-clock-effort
 	(let* ((effort-in-minutes
-		(org-duration-string-to-minutes org-clock-effort))
+		(org-clocksum-string-to-minutes org-clock-effort))
 	       (work-done-str
 		(org-propertize
 		 (org-minutes-to-clocksum-string clocked-time)
@@ -744,10 +744,10 @@ clocked item, and the value displayed in the mode line."
 	  ;; A string.  See if it is a delta
 	  (setq sign (string-to-char value))
 	  (if (member sign '(?- ?+))
-	      (setq current (org-duration-string-to-minutes current)
+	      (setq current (org-clocksum-string-to-minutes current)
 		    value (substring value 1))
 	    (setq current 0))
-	  (setq value (org-duration-string-to-minutes value))
+	  (setq value (org-clocksum-string-to-minutes value))
 	  (if (equal ?- sign)
 	      (setq value (- current value))
 	    (if (equal ?+ sign) (setq value (+ current value)))))
@@ -765,7 +765,7 @@ clocked item, and the value displayed in 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-duration-string-to-minutes org-clock-effort))
+    (let ((effort-in-minutes (org-clocksum-string-to-minutes org-clock-effort))
 	  (clocked-time (org-clock-get-clocked-time)))
       (if (setq org-clock-task-overrun
 		(if (or (null effort-in-minutes) (zerop effort-in-minutes))
@@ -1187,7 +1187,7 @@ make this the default behavior.)"
   (setq org-clock-notification-was-shown nil)
   (org-refresh-properties
    org-effort-property '((effort . identity)
-			 (effort-minutes . org-duration-string-to-minutes)))
+			 (effort-minutes . org-clocksum-string-to-minutes)))
   (catch 'abort
     (let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
 			     (org-clocking-p)))
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index e157031..a3ce406 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1110,7 +1110,7 @@ display, or in the #+COLUMNS line of the current buffer."
        ((string-match (concat "\\([0-9.]+\\) *\\("
 			      (regexp-opt (mapcar 'car org-effort-durations))
 			      "\\)") s)
-	(setq s (concat "0:" (org-duration-string-to-minutes s t)))
+	(setq s (concat "0:" (org-clocksum-string-to-minutes s t)))
         (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
           (while l
             (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
diff --git a/lisp/org.el b/lisp/org.el
index f6c513e..24f81e4 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3677,7 +3677,7 @@ and the clock summary:
 
  ((\"Remaining\" (lambda(value)
                    (let ((clocksum (org-clock-sum-current-item))
-                         (effort (org-duration-string-to-minutes
+                         (effort (org-clocksum-string-to-minutes
                                    (org-entry-get (point) \"Effort\"))))
                      (org-minutes-to-clocksum-string (- effort clocksum))))))"
   :group 'org-properties
@@ -9574,7 +9574,7 @@ The refresh happens only for the current tree (not subtree)."
   (org-refresh-properties
    org-effort-property
    '((effort . identity)
-     (effort-minutes . org-duration-string-to-minutes))))
+     (effort-minutes . org-clocksum-string-to-minutes))))
 
 ;;;; Link Stuff
 
@@ -15645,7 +15645,7 @@ When INCREMENT is non-nil, set the property to the next allowed value."
       (org-entry-put nil prop val))
     (org-refresh-property
      '((effort . identity)
-       (effort-minutes . org-duration-string-to-minutes))
+       (effort-minutes . org-clocksum-string-to-minutes))
      val)
     (when (string= heading org-clock-current-task)
       (setq org-clock-effort (get-text-property (point-at-bol) 'effort))
@@ -16506,7 +16506,7 @@ completion."
     (when (equal prop org-effort-property)
       (org-refresh-property
        '((effort . identity)
-	 (effort-minutes . org-duration-string-to-minutes))
+	 (effort-minutes . org-clocksum-string-to-minutes))
        nval)
       (when (string= org-clock-current-task heading)
 	(setq org-clock-effort nval)
@@ -18303,7 +18303,7 @@ 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 &optional output-to-string)
+(defun org-clocksum-string-to-minutes (s &optional output-to-string)
   "Convert a duration string S to minutes.
 
 A bare number is interpreted as minutes, modifiers can be set by
@@ -18323,6 +18323,10 @@ Entries containing a colon are interpreted as H:MM by
     (incf result (org-hh:mm-string-to-minutes s))
     (if output-to-string (number-to-string result) result)))
 
+(define-obsolete-function-alias
+  'org-duration-string-to-minutes
+  'org-clocksum-string-to-minutes "Org mode version 8.3")
+
 (defcustom org-image-actual-width t
   "Should we use the actual width of images when inlining them?
 
-- 
2.6.4

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

* [PATCH 3/4] simplify and document `org-effort-durations'-related code
  2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 2/4] rename `org-duration-string-to-minutes' to `org-clocksum-string-to-minutes' everywhere Jan Malakhovski
@ 2015-12-27 15:13 ` Jan Malakhovski
  2015-12-27 15:13 ` [PATCH 4/4] org-clock: make clock table respect `org-effort-durations' Jan Malakhovski
  3 siblings, 0 replies; 5+ messages in thread
From: Jan Malakhovski @ 2015-12-27 15:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Jan Malakhovski

* lisp/org.el (org-time-clocksum-use-effort-durations): Make obsolete.
(org-effort-durations-default):
(org-effort-durations-8h):
(org-effort-durations-6h): New constants.
(org-effort-durations): Redefine and document.
(org-minutes-to-clocksum-string): Simplify.
* lisp/org-agenda.el: (org-agenda-show-clocking-issues):
(org-agenda-format-item): Use new constants.
* lisp/org.el:
* lisp/org-clock.el:
* lisp/org-colview.el: Document everything related to (org-effort-durations) a bit better.
---
 lisp/org-agenda.el  |   4 +-
 lisp/org-clock.el   |   5 ++-
 lisp/org-colview.el |   1 +
 lisp/org.el         | 118 ++++++++++++++++++++++++++++++++--------------------
 4 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 99ccedd..d8f9a96 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5922,7 +5922,7 @@ please use `org-class' instead."
   "Add overlays, showing issues with clocking.
 See also the user option `org-agenda-clock-consistency-checks'."
   (interactive)
-  (let* ((org-time-clocksum-use-effort-durations nil)
+  (let* ((org-effort-durations org-effort-durations-default)
 	 (pl org-agenda-clock-consistency-checks)
 	 (re (concat "^[ \t]*"
 		     org-clock-string
@@ -6550,7 +6550,7 @@ Any match of REMOVE-RE will be removed from TXT."
 	  (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
 
 	  ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
-	  (let (org-time-clocksum-use-effort-durations)
+	  (let (org-effort-durations org-effort-durations-default)
 	    (when (and s1 (not s2) org-agenda-default-appointment-duration)
 	      (setq s2
 		    (org-minutes-to-clocksum-string
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index b7a70dc..df993b0 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -724,8 +724,8 @@ previous clocking intervals."
 VALUE can be a number of minutes, or a string with format hh:mm or mm.
 When the string starts with a + or a - sign, the current value of the effort
 property will be changed by that amount.  If the effort value is expressed
-as an `org-effort-durations' (e.g. \"3h\"), the modified value will be
-converted to a hh:mm duration.
+using modifiers (e.g. \"3h\", see `org-clocksum-string-to-minutes'), the
+modified value will be converted to a hh:mm duration.
 
 This command will update the \"Effort\" property of the currently
 clocked item, and the value displayed in the mode line."
@@ -2468,6 +2468,7 @@ from the dynamic block definition."
 	 (maxlevel (or (plist-get params :maxlevel) 3))
 	 (emph (plist-get params :emphasize))
 	 (level-p (plist-get params :level))
+	 ;; FIXME: setting this will break `org-clock-time%'
 	 (org-time-clocksum-use-effort-durations
 	  (plist-get params :effort-durations))
 	 (timestamp (plist-get params :timestamp))
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index a3ce406..f6ad85e 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1107,6 +1107,7 @@ display, or in the #+COLUMNS line of the current buffer."
        ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
         (if (equal s "[X]") 1. 0.000001))
        ((memq fmt '(estimate)) (org-string-to-estimate s))
+       ;; FIXME: this is ugly
        ((string-match (concat "\\([0-9.]+\\) *\\("
 			      (regexp-opt (mapcar 'car org-effort-durations))
 			      "\\)") s)
diff --git a/lisp/org.el b/lisp/org.el
index 24f81e4..e3f6bb6 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3145,8 +3145,13 @@ commands, if custom time display is turned on at the time of export."
 
 (defcustom org-time-clocksum-format
   '(:days "%dd " :hours "%d" :require-hours t :minutes ":%02d" :require-minutes t)
-  "The format string used when creating CLOCKSUM lines.
-This is also used when Org mode generates a time duration.
+  "The format string used when creating CLOCKSUM lines and time
+durations (see `org-minutes-to-clocksum-string').
+
+Note, that setting this to something that
+`org-clocksum-string-to-minutes' can not parse and invert will
+confuse time computations that go through text representation
+phase (e.g. time percent computations in clock reports/tables).
 
 The value can be a single format string containing two
 %-sequences, which will be filled with the number of hours and
@@ -3156,8 +3161,9 @@ Alternatively, the value can be a plist associating any of the
 keys :years, :months, :weeks, :days, :hours or :minutes with
 format strings.  The time duration is formatted using only the
 time components that are needed and concatenating the results.
-If a time unit in absent, it falls back to the next smallest
-unit.
+If a time unit (modifier) in absent, it falls back to the next
+smallest modifier. The length of each modifier is defined by
+`org-effort-durations'.
 
 The keys :require-years, :require-months, :require-days,
 :require-weeks, :require-hours, :require-minutes are also
@@ -3168,7 +3174,7 @@ its value is 0.
 
 For example,
 
-   (:days \"%dd\" :hours \"%d\" :require-hours t :minutes \":%02d\"
+   (:days \"%dd \" :hours \"%d\" :require-hours t :minutes \":%02d\"
     :require-minutes t)
 
 means durations longer than a day will be expressed in days,
@@ -3178,7 +3184,7 @@ hour).
 
 The value
 
-  (:days \"%dd\" :minutes \"%dm\")
+  (:days \"%dd \" :minutes \"%dmin\")
 
 means durations longer than a day will be expressed in days and
 minutes, and durations less than a day will be expressed entirely
@@ -3220,6 +3226,10 @@ in minutes (even for durations longer than an hour)."
 			     (const :tag "Always show minutes" :require-minutes)
 			     (const t)))))
 
+(make-obsolete-variable
+ 'org-time-clocksum-use-effort-durations
+ "Set `org-effort-durations' directly instead." "Org mode version 8.3")
+
 (defcustom org-time-clocksum-use-fractional nil
   "When non-nil, \\[org-clock-display] uses fractional times.
 See `org-time-clocksum-format' for more on time clock formats."
@@ -3228,20 +3238,6 @@ See `org-time-clocksum-format' for more on time clock formats."
   :version "24.3"
   :type 'boolean)
 
-(defcustom org-time-clocksum-use-effort-durations nil
-  "When non-nil, \\[org-clock-display] uses effort durations.
-E.g. by default, one day is considered to be a 8 hours effort,
-so a task that has been clocked for 16 hours will be displayed
-as during 2 days in the clock display or in the clocktable.
-
-See `org-effort-durations' on how to set effort durations
-and `org-time-clocksum-format' for more on time clock formats."
-  :group 'org-time
-  :group 'org-clock
-  :version "24.4"
-  :package-version '(Org . "8.0")
-  :type 'boolean)
-
 (defcustom org-time-clocksum-fractional-format "%.2f"
   "The format string used when creating CLOCKSUM lines,
 or when Org mode generates a time duration, if
@@ -18169,48 +18165,80 @@ If there is already a time stamp at the cursor position, update it."
       (org-insert-time-stamp
        (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
 
-(defcustom org-effort-durations
+(defconst org-effort-durations-default
+  `(("min" . 1)
+    ("h" . 60)
+    ("d" . ,(* 60 24))
+    ("w" . ,(* 60 24 7))
+    ("m" . ,(* 60 24 30))
+    ("y" . ,(* 60 24 365)))
+  "The conventional '24-hours-a-day, 7-days-a-week, 30-days-a-month, 365-days-a-year' definition of `org-effort-durations'.")
+
+(defconst org-effort-durations-8h
   `(("min" . 1)
     ("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.
+  "The '8-hours-a-day, 5-days-a-week, 4-weeks-a-month, 40-weeks-a-year' definition of `org-effort-durations'.")
+
+(defconst org-effort-durations-6h
+  `(("min" . 1)
+    ("h" . 60)
+    ("d" . ,(* 60 6))
+    ("w" . ,(* 60 6 5))
+    ("m" . ,(* 60 6 5 4))
+    ("y" . ,(* 60 6 5 40)))
+  "The '6-hours-a-day, 5-days-a-week, 4-weeks-a-month, 40-weeks-a-year' definition of `org-effort-durations'.")
+
+(defcustom org-effort-durations
+  org-effort-durations-default
+  "Conversion factor to minutes for an effort unit (modifier)
+used by `org-minutes-to-clocksum-string' and
+`org-clocksum-string-to-minutes'.
 
 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.
+by the specified number of MINUTES to obtain an effort in minutes
+and vice versa.
 
-For example, if the value of this variable is ((\"hours\" . 60)), then an
-effort string \"2hours\" is equivalent to 120 minutes."
+This variable is required to define at least 'h', 'd', 'w', 'm',
+and 'y' modifiers since they are referenced in the definition of
+`org-minutes-to-clocksum-string'. The latter function ignores
+other modifiers, but `org-clocksum-string-to-minutes' uses them
+all when possible.
+
+The default value is `org-effort-durations-default', but there
+are also handy commonly used `org-effort-durations-8h' and
+`org-effort-durations-6h'."
   :group 'org-agenda
+  :group 'org-time
+  :group 'org-clock
   :version "25.1"
   :package-version '(Org . "8.3")
-  :type '(alist :key-type (string :tag "Modifier")
-		:value-type (number :tag "Minutes")))
+  :type `(choice (const :tag "24-hours-a-day, 7-days-a-week, 30-days-a-month, 365-days-a-year" ,org-effort-durations-default)
+		 (const :tag "8-hours-a-day, 5-days-a-week, 4-weeks-a-month, 40-weeks-a-year" ,org-effort-durations-8h)
+		 (const :tag "6-hours-a-day, 5-days-a-week, 4-weeks-a-month, 40-weeks-a-year" ,org-effort-durations-6h)
+		 (alist :tag "Custom"
+			:key-type (string :tag "Modifier")
+			:value-type (number :tag "Minutes"))))
 
 (defun org-minutes-to-clocksum-string (m)
   "Format number of minutes as a clocksum string.
 The format is determined by `org-time-clocksum-format',
+`org-effort-durations',
 `org-time-clocksum-use-fractional' and
-`org-time-clocksum-fractional-format' and
-`org-time-clocksum-use-effort-durations'."
-  (let ((clocksum "")
-	(m (round m)) ; Don't allow fractions of minutes
-	h d w mo y fmt n)
-    (setq h (if org-time-clocksum-use-effort-durations
-		(cdr (assoc "h" org-effort-durations)) 60)
-	  d (if org-time-clocksum-use-effort-durations
-		(/ (cdr (assoc "d" org-effort-durations)) h) 24)
-	  w (if org-time-clocksum-use-effort-durations
-		(/ (cdr (assoc "w" org-effort-durations)) (* d h)) 7)
-	  mo (if org-time-clocksum-use-effort-durations
-		 (/ (cdr (assoc "m" org-effort-durations)) (* d h)) 30)
-	  y (if org-time-clocksum-use-effort-durations
-		(/ (cdr (assoc "y" org-effort-durations)) (* d h)) 365))
+`org-time-clocksum-fractional-format'."
+  (let* ((clocksum "")
+	 (m (round m)) ; Don't allow fractions of minutes
+	 (h (cdr (assoc "h" org-effort-durations)))
+	 (d (/ (cdr (assoc "d" org-effort-durations)) h))
+	 (w (/ (cdr (assoc "w" org-effort-durations)) (* d h)))
+	 (mo (/ (cdr (assoc "m" org-effort-durations)) (* d h)))
+	 (y (/ (cdr (assoc "y" org-effort-durations)) (* d h)))
+	 fmt n)
     ;; fractional format
     (if org-time-clocksum-use-fractional
 	(cond
@@ -18306,8 +18334,8 @@ If no number is found, the return value is 0."
 (defun org-clocksum-string-to-minutes (s &optional output-to-string)
   "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).
+A bare number is interpreted as minutes, units (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'."
-- 
2.6.4

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

* [PATCH 4/4] org-clock: make clock table respect `org-effort-durations'
  2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
                   ` (2 preceding siblings ...)
  2015-12-27 15:13 ` [PATCH 3/4] simplify and document `org-effort-durations'-related code Jan Malakhovski
@ 2015-12-27 15:13 ` Jan Malakhovski
  3 siblings, 0 replies; 5+ messages in thread
From: Jan Malakhovski @ 2015-12-27 15:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Jan Malakhovski

* lisp/org-clock.el (org-clock-time%): Rewrite using (org-clocksum-string-to-minutes), document pitfalls.
(org-clock-time%-with-effort): New function.
(org-clocktable-write-default): Fix effort-duration parameter.
* doc/org.texi (The clock table): Update documentation.
---
 doc/org.texi      |  6 ++++++
 lisp/org-clock.el | 49 ++++++++++++++++++++++++++++---------------------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 92ec29a..c526057 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6687,6 +6687,7 @@ but you can specify your own function using the @code{:formatter} parameter.
              @r{As a special case, @samp{:formula %} adds a column with % time.}
              @r{If you do not specify a formula here, any existing formula}
              @r{below the clock table will survive updates and be evaluated.}
+:effort-durations @r{Name of a symbol to use as @code{org-effort-durations} when preparing the table.}
 :formatter   @r{A function to format clock data and insert it into the buffer.}
 @end example
 To get a clock summary of the current level 1 tree, for the current
@@ -6714,6 +6715,11 @@ A summary of the current subtree with % times would be
 #+BEGIN: clocktable :scope subtree :link t :formula %
 #+END: clocktable
 @end example
+The same thing measured in 8-hour work days would be
+@example
+#+BEGIN: clocktable :scope subtree :link t :formula % :effort-durations org-effort-durations-8h
+#+END: clocktable
+@end example
 A horizontally compact representation of everything clocked during last week
 would be
 @example
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index df993b0..53292ae 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2468,9 +2468,10 @@ from the dynamic block definition."
 	 (maxlevel (or (plist-get params :maxlevel) 3))
 	 (emph (plist-get params :emphasize))
 	 (level-p (plist-get params :level))
-	 ;; FIXME: setting this will break `org-clock-time%'
-	 (org-time-clocksum-use-effort-durations
-	  (plist-get params :effort-durations))
+	 (effort-durations (plist-get params :effort-durations))
+	 (org-effort-durations (if (null effort-durations)
+				   org-effort-durations
+				   (eval effort-durations)))
 	 (timestamp (plist-get params :timestamp))
 	 (properties (plist-get params :properties))
 	 (ntcol (max 1 (or (plist-get params :tcolumns) 100)))
@@ -2641,8 +2642,11 @@ from the dynamic block definition."
 			(if timestamp 1 0)))
 	  (insert
 	   (format
-	    "\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
+	    "\n#+TBLFM: $%d='(%s @%d$%d $%d..$%d);%%.1f"
 	    pcol            ; the column where the % numbers should go
+	    (if (null effort-durations)
+		"org-clock-time%"
+		(format "org-clock-time%%-with-effort %s" (symbol-name effort-durations)))
 	    (if (and narrow (not narrow-cut-p)) 3 2) ; row of the total time
 	    tcol            ; column of the total time
 	    tcol (1- pcol)  ; range of columns where times can be found
@@ -2858,25 +2862,28 @@ TIME:      The sum of all time spend in this tree, in minutes.  This time
   "Compute a time fraction in percent.
 TOTAL s a time string like 10:21 specifying the total times.
 STRINGS is a list of strings that should be checked for a time.
+Strings are parsed using `org-clocksum-string-to-minutes'.
 The first string that does have a time will be used.
-This function is made for clock tables."
-  (let ((re "\\([0-9]+\\):\\([0-9]+\\)")
-	tot s)
-    (save-match-data
+
+This function is made for clock tables.
+
+This function can be broken by setting `org-time-clocksum-format'
+to something that `org-clocksum-string-to-minutes' can not
+parse."
+  (save-match-data
+    (let ((tot (org-clocksum-string-to-minutes total))
+	   s cur)
       (catch 'exit
-	(if (not (string-match re total))
-	    (throw 'exit 0.)
-	  (setq tot (+ (string-to-number (match-string 2 total))
-		       (* 60 (string-to-number (match-string 1 total)))))
-	  (if (= tot 0.) (throw 'exit 0.)))
-	(while (setq s (pop strings))
-	  (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
-	      (throw 'exit
-		     (/ (* 100.0 (+ (string-to-number (match-string 2 s))
-				    (* 60 (string-to-number
-					   (match-string 1 s)))))
-			tot))))
-	0))))
+	(if (= tot 0.) (throw 'exit 0.))
+	(dolist (s strings)
+	  (setq cur (org-clocksum-string-to-minutes s))
+	  (when cur (throw 'exit (/ (* 100.0 cur) tot))))
+	nil))))
+
+(defun org-clock-time%-with-effort (effort-durations total &rest strings)
+  "A version of `org-clock-time%' that temporary sets `org-effort-durations'."
+  (let ((org-effort-durations effort-durations))
+    (apply 'org-clock-time% total strings)))
 
 ;; Saving and loading the clock
 
-- 
2.6.4

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

end of thread, other threads:[~2015-12-27 15:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-27 15:13 [PATCH v3 part3 0/4] fixing org-clock-time% Jan Malakhovski
2015-12-27 15:13 ` [PATCH 1/4] org: move `org-duration-string-to-minutes' to a better place Jan Malakhovski
2015-12-27 15:13 ` [PATCH 2/4] rename `org-duration-string-to-minutes' to `org-clocksum-string-to-minutes' everywhere Jan Malakhovski
2015-12-27 15:13 ` [PATCH 3/4] simplify and document `org-effort-durations'-related code Jan Malakhovski
2015-12-27 15:13 ` [PATCH 4/4] org-clock: make clock table respect `org-effort-durations' Jan Malakhovski

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