Hi all,
I'm new to this list and joined in order to submit the attached tiny patch.
As per https://orgmode.org/manual/Column-attributes.html I'm using range
durations to express effort estimations. Those get summarized nicely in
column views, using the {est+} summarizer. But when I access an agenda
view that encounters a task that has such a range duration directly set,
the agenda chokes with an error message:
org-duration-to-minutes: Invalid duration format: "1d-2d"
Attached patch fixes that error, by
1. Just before throwing that error, checking if this is potentially a
range duration, of two durations separated by a "-"
2. If so, split the range into two separate <low> and <high> durations,
convert each of those to minutes, and take the average.
The patch doesn't use a fancy regexp. Instead, it recurses into
org-duration-to-minutes and reapplies all sanity checks on the
constituent low/high durations. If you have two valid durations
connected by a dash (and optionally whitespace), that's a valid range
duration, and it will be expressed as a float. If not, you'll hit the
error fallback directly below.
Applying this patch fixes my agenda view when using range durations.
Since the actual code change is just 2 lines, I opted to forego the FSF
copyright assignment caroussel by marking this a TINYCHANGE.
Patch is based off e269942a353965dd8bdad57741adc9c53116a08a which is my
current Doom Emacs checkout of
https://github.com/emacs-straight/org-mode. I hope that's fine.
Kind regards, Guido.
--
Guido Stevens | Cosent | https://cosent.nl
s o c i a l k n o w l e d g e t e c h n o l o g y
From 772ca4c915a629a62be0b5ee64005a929bf1bf04 Mon Sep 17 00:00:00 2001
From: "Guido A.J. Stevens" <guido.stev...@cosent.nl>
Date: Wed, 11 Sep 2024 13:24:58 +0200
Subject: [PATCH] lisp/org-duration.el: support range durations
* lisp/org-duration.el (org-duration-to-minutes): Do not choke on
low-high range durations (e.g. "2d-5d") when rendering an agenda. Calculate the average
of the range instead.
Range durations are valid when estimating effort, and supported
elsewhere via the {est+} summarizer.
TINYCHANGE
---
lisp/org-duration.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/org-duration.el b/lisp/org-duration.el
index 662a94bd5..46771a355 100644
--- a/lisp/org-duration.el
+++ b/lisp/org-duration.el
@@ -283,7 +283,7 @@ When optional argument CANONICAL is non-nil, ignore
`org-duration-units' and use standard time units value.
A bare number is translated into minutes. The empty string is
-translated into 0.0.
+translated into 0.0. A low - high range duration is averaged.
Return value as a float. Raise an error if duration format is
not recognized."
@@ -311,6 +311,8 @@ not recognized."
(org-duration-to-minutes hms-part))))
((string-match-p "\\`[0-9]+\\(\\.[0-9]*\\)?\\'" duration)
(float (string-to-number duration)))
+ ((string-match-p "-" duration)
+ (pcase-let ((`(,low ,high) (mapcar #'org-duration-to-minutes (split-string duration "-")))) (/ (+ low high) 2)))
(t (error "Invalid duration format: %S" duration)))))
;;;###autoload
--
2.43.0