From 2b02f45a1bacf0b0c705b9d0a3e5fdfc40edc523 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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index e311e7f..201a56b 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -847,6 +847,32 @@ 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. + +The result 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 + (setq 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