From fa6bd0e713788f74accaabc6af0051bd96b69fa3 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 5 Oct 2024 14:20:35 +0200 Subject: [PATCH] Introduce first draft to compute time spent on work today This is supposed to be used later on in workload overview reports, to make the display of the current day account for already spent time. --- site-lisp/db-org.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index e311e7f..947911d 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -847,6 +847,33 @@ PARAMS is a property list of the following parameters: (org-dynamic-block-define "db/org-workload-overview-report" #'db/org-insert-workload-overview-report) +(defun db/spent-work-hours-today (&optional match) + "Return the time spent today on work. + +Relevant clock times are taken from the file in +`org-agenda-files'. The result returned is given as integer in +minutes. + +MATCH is a Org properties match that determines what constitutes +as work item. When not given, defaults to all tasks except those +given by `org-home-task-id' and `org-break-task-id'." + (unless match + (when (and (stringp org-home-task-id) + (not (zerop (length org-home-task-id)))) + (setq match (concat match (format "-ID=%s" org-home-task-id)))) + (when (and (stringp org-break-task-id) + (not (zerop (length org-break-task-id)))) + (setq match (concat match (format "-ID=%s" org-break-task-id))))) + (->> org-agenda-files + (-map #'(lambda (file) ; taken from `org-dblock-write:clocktable' + (with-current-buffer (find-buffer-visiting file) + (save-excursion + (save-restriction + (org-clock-get-table-data file (list :match match + :block 'today))))))) + (-map #'cl-second) + -sum)) + ;;; Fixes