Fix off-by-one error in workload overview report

Found that the report will only produce reasonable output when always working on
00:00.  Left a note in the docstring to warn about this, should be fixed later on.
This commit is contained in:
Daniel - 2023-01-16 17:26:32 +01:00
parent c1476df9e8
commit 4e5cad2842
Signed by: dbo
GPG Key ID: 784AA8DF0CCDF625
1 changed files with 13 additions and 10 deletions

View File

@ -541,6 +541,9 @@ understood by `org-read-date'."
(defun org-dblock-write:db/org-workload-overview-report (params) (defun org-dblock-write:db/org-workload-overview-report (params)
"Write an overview workload report based on tasks in `org-agenda-files'. "Write an overview workload report based on tasks in `org-agenda-files'.
FIXME: this function is buggy, it is not treating the time-parts
correctly. Use with care!
This overview report will list the amount of work planned for This overview report will list the amount of work planned for
increasing intervals of time until a given end date is reached. increasing intervals of time until a given end date is reached.
For example, if the amount to increase the intervals is two For example, if the amount to increase the intervals is two
@ -574,7 +577,7 @@ PARAMS is a property list of the following parameters:
tasks to consider. Defaults to (todo)." tasks to consider. Defaults to (todo)."
(let* ((start-date (or (--if-let (plist-get params :start-date) (let* ((start-date (or (--if-let (plist-get params :start-date)
(org-read-date nil nil it)) (org-read-date nil nil it))
nil)) (org-read-date t nil ". 00:00")))
(end-date (or (--if-let (plist-get params :end-date) (end-date (or (--if-let (plist-get params :end-date)
(org-read-date nil nil it)) (org-read-date nil nil it))
(user-error "No valid end-date provided"))) (user-error "No valid end-date provided")))
@ -582,8 +585,7 @@ PARAMS is a property list of the following parameters:
"+1d")) "+1d"))
(org-ql-match (or (plist-get params :org-ql-match) (org-ql-match (or (plist-get params :org-ql-match)
'(todo))) '(todo)))
(current (or start-date (current start-date)
(org-read-date nil nil ". 00:00")))
(date-range nil)) (date-range nil))
;; Check input ;; Check input
@ -605,24 +607,25 @@ PARAMS is a property list of the following parameters:
;; maybe consider `org-read-date-get-relative' as well? ;; maybe consider `org-read-date-get-relative' as well?
(while (or (string< current end-date) (while (or (string< current end-date)
(string= current end-date)) (string= current end-date))
(push current date-range)
(setq current (org-read-date nil (setq current (org-read-date nil
nil nil
;; Add an extra + to ensure we increase the ;; Add an extra + to ensure we increase the
;; default time string.
;; amount of time relative to the given ;; amount of time relative to the given
;; default time string.
(format "+%s" increment) (format "+%s" increment)
nil nil
(org-time-string-to-time current)))) (org-time-string-to-time current)))
(push current date-range))
(setq date-range (nreverse date-range)) (setq date-range (nreverse date-range))
(insert (format "#+CAPTION: Workload Overview Report at %s.\n" (insert (format "#+CAPTION: Workload Overview Report at %s with start date [%s]\n"
(with-temp-buffer (with-temp-buffer
;; Is there an easier way to get the current time as an ;; Is there an easier way to get the current time as an
;; inactive timestamp? ;; inactive timestamp?
(org-insert-time-stamp (current-time) t t) (org-insert-time-stamp (current-time) t t)
(buffer-string)))) (buffer-string))
(insert "| Until | Planned Total |\n| <r> | <r> |\n|---|\n") start-date))
(insert "| End Time | Planned Total |\n| <r> | <r> |\n|---|\n")
;; Compute workload report for each date and record the total time; XXX: ;; Compute workload report for each date and record the total time; XXX:
;; this might be slow, try to reduce the calls to ;; this might be slow, try to reduce the calls to
;; `db/org-planned-tasks-in-range'. ;; `db/org-planned-tasks-in-range'.
@ -631,7 +634,7 @@ PARAMS is a property list of the following parameters:
interval-end-date interval-end-date
org-ql-match)))) org-ql-match))))
(insert "| ") (insert "| ")
(org-insert-time-stamp (org-time-string-to-time interval-end-date) nil 'inactive) (org-insert-time-stamp (org-time-string-to-time interval-end-date) t 'inactive)
(insert (format " | %s |\n" total-time)))) (insert (format " | %s |\n" total-time))))
(insert "|--|") (insert "|--|")
(org-table-align))) (org-table-align)))