From: Guido Stevens <guido.stevens@cosent.net>
To: emacs-orgmode@gnu.org
Subject: support range durations
Date: Wed, 11 Sep 2024 14:01:18 +0200 [thread overview]
Message-ID: <ca76997e-6571-4817-8b9d-8cbf350fd1e2@cosent.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1659 bytes --]
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
[-- Attachment #2: 0001-lisp-org-duration.el-support-range-durations.patch --]
[-- Type: text/x-patch, Size: 1544 bytes --]
From 772ca4c915a629a62be0b5ee64005a929bf1bf04 Mon Sep 17 00:00:00 2001
From: "Guido A.J. Stevens" <guido.stevens@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
next reply other threads:[~2024-09-11 12:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 12:01 Guido Stevens [this message]
2024-09-15 12:02 ` support range durations Ihor Radchenko
2024-09-16 8:41 ` Guido Stevens
2024-09-22 7:56 ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 (was: support range durations) Ihor Radchenko
2024-09-23 12:21 ` [BUG] Regression: org-duration fails to support duration ranges since Org 9.0.6 Guido Stevens
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca76997e-6571-4817-8b9d-8cbf350fd1e2@cosent.net \
--to=guido.stevens@cosent.net \
--cc=emacs-orgmode@gnu.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.