From 9e3fe2a3b06946e1f5fe3c379bd491415a1e1ca9 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Thu, 3 Oct 2024 18:01:02 +0200 Subject: [PATCH] Allow to specify available work hours using custom functions This allows to specify variable work hours depending on the corresponding date. --- site-lisp/db-org.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 1334fd2..e311e7f 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -772,8 +772,12 @@ PARAMS is a property list of the following parameters: #'(lambda (x) (string-match arg x))) ((and (pred functionp) fun) fun) (arg (user-error "Invalid argument to :skip-matches: %s" arg)))) - (work-hours (or (plist-get params :work-hours) - "8:00")) + (work-hours (pcase (plist-get params :work-hours) + ((pred null) #'(lambda (_) "8:00")) + ((and (pred org-duration-p) arg) + #'(lambda (_) arg)) + ((and (pred functionp) fun) fun) + (arg (user-error "Invalid argument to :work-hours: %s" arg)))) date-range) ;; Check input @@ -782,9 +786,6 @@ PARAMS is a property list of the following parameters: increment) (user-error "Increment must be of the form +1d, +2m, +3y, …, but it's %s" increment)) - (unless (org-duration-p work-hours) - (user-error "Work hours must be a duration string, but it's %s" work-hours)) - ;; Compute range of dates to check; simple but potentially costly approach ;; taken from https://sachachua.com/blog/2015/08/org-mode-date-arithmetic/; ;; maybe consider `org-read-date-get-relative' as well? @@ -819,7 +820,9 @@ PARAMS is a property list of the following parameters: interval-end-date org-ql-match))) (utilization (* (/ (org-duration-to-minutes total-time-duration) - (cl-incf total-work-hours (org-duration-to-minutes work-hours))) + (cl-incf total-work-hours + (org-duration-to-minutes + (funcall work-hours interval-end-date)))) 100))) (insert (format "| [%s] | %s | %s | %s |\n" interval-end-date