Compare commits

...

2 Commits

Author SHA1 Message Date
e5577f8094
Fix org-read-date not recognizing hh:mm parts on startup
The problem seems to be the dynamically scoped variable `org-time-was-given`,
which is used by `org-read-date` to decided whether an hh:mm part is present.
The variable `org-time-was-given` is set by `org-read-date-analyze`, but only
when it's (globally) bound, which it is not on startup (since it's only declared
via `defvar`).  Manually setting the variable to nil binds the variable and
everything seems to work nicely.
2023-01-16 19:13:26 +01:00
bb7da2e08e
Change timestamp format in workload overview report to internal time
`org-read-date` seems to have bug that it does not consider the hh:mm part of an
input string sometimes.  Trying to work around this by using internal times
whenever possible, but it's not complete yet.
2023-01-16 19:09:04 +01:00
2 changed files with 34 additions and 40 deletions

10
init.el
View File

@ -977,7 +977,15 @@
;; Caching is not possible, check it directly. ;; Caching is not possible, check it directly.
(org-entry-get pom property 'inherit) (org-entry-get pom property 'inherit)
;; This is different in the original implementation ;; This is different in the original implementation
(org-entry-get pom property)))))) (org-entry-get pom property))))
;; Fix (Org 9.5.5): the variable `org-time-was-given' dynamically
;; bound to signify when `org-read-date-analyze' has found a hh:mm
;; part; it's only considered, however, when it has previously been
;; bound, resulting in some prior calls of `org-read-date' to ignore
;; the hh:mm part. So let's bind this variable now to make things
;; work.
(setq org-time-was-given nil)))
;; Drag-and-Drop images into org-mode buffer ;; Drag-and-Drop images into org-mode buffer
(use-package org-download (use-package org-download

View File

@ -575,29 +575,20 @@ PARAMS is a property list of the following parameters:
`org-ql' expression (in sexp syntax) to filter the list of `org-ql' expression (in sexp syntax) to filter the list of
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 (org-read-date t t
(org-read-date nil nil it)) (or (plist-get params :start-date)
(org-read-date t nil ". 00:00"))) "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 t t it))
(user-error "No valid end-date provided"))) (user-error "No valid end-date provided")))
(increment (or (plist-get params :increment) (increment (or (plist-get params :increment)
"+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 start-date) (timestamp-format "%Y-%m-%d %a %H:%M")
(date-range nil)) date-range)
;; Check input ;; Check input
(unless (or (null start-date)
(string-match-p (org-re-timestamp 'inactive)
(format "[%s]" start-date)))
(user-error "Invalid start date given: %s" start-date))
(unless (string-match-p (org-re-timestamp 'inactive)
(format "[%s]" end-date))
(user-error "Invalid end date given: %s" end-date))
(unless (string-match-p (rx bos "+" (+ digit) (in "dwmy") eos) (unless (string-match-p (rx bos "+" (+ digit) (in "dwmy") eos)
increment) increment)
(user-error "Increment must be of the form +1d, +2m, +3y, …, but it's %s" increment)) (user-error "Increment must be of the form +1d, +2m, +3y, …, but it's %s" increment))
@ -605,37 +596,32 @@ PARAMS is a property list of the following parameters:
;; Compute range of dates to check; simple but potentially costly approach ;; Compute range of dates to check; simple but potentially costly approach
;; taken from https://sachachua.com/blog/2015/08/org-mode-date-arithmetic/; ;; taken from https://sachachua.com/blog/2015/08/org-mode-date-arithmetic/;
;; maybe consider `org-read-date-get-relative' as well? ;; maybe consider `org-read-date-get-relative' as well?
(while (or (string< current end-date) (let ((current start-date))
(string= current end-date)) (while (or (time-less-p current end-date)
(setq current (org-read-date nil (time-equal-p current end-date))
nil (setq current (org-read-date t t
;; Add an extra + to ensure we increase the ;; Add an extra + to ensure we increase the
;; amount of time relative to the given ;; amount of time relative to the given
;; default time string. ;; default time string.
(format "+%s" increment) (format "+%s" increment)
nil nil current))
(org-time-string-to-time current))) (push current date-range)))
(push current date-range))
(setq date-range (nreverse date-range)) (setq date-range (nreverse date-range))
(insert (format "#+CAPTION: Workload Overview Report at %s with start date [%s]\n" (insert (format "#+CAPTION: Workload Overview Report at %s with start date [%s]\n"
(with-temp-buffer (format-time-string timestamp-format (current-time))
;; Is there an easier way to get the current time as an (format-time-string timestamp-format start-date)))
;; inactive timestamp?
(org-insert-time-stamp (current-time) t t)
(buffer-string))
start-date))
(insert "| End Time | Planned Total |\n| <r> | <r> |\n|---|\n") (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;
;; this might be slow, try to reduce the calls to ;; XXX: this might be slow, try to reduce the calls to
;; `db/org-planned-tasks-in-range'. ;; `db/org-planned-tasks-in-range'.
(dolist (interval-end-date date-range) (dolist (interval-end-date date-range)
(let ((total-time (car (db/org-planned-tasks-in-range start-date (let ((total-time (car (db/org-planned-tasks-in-range (format-time-string timestamp-format start-date)
interval-end-date (format-time-string timestamp-format interval-end-date)
org-ql-match)))) org-ql-match))))
(insert "| ") (insert (format "| [%s] | %s |\n"
(org-insert-time-stamp (org-time-string-to-time interval-end-date) t 'inactive) (format-time-string timestamp-format interval-end-date)
(insert (format " | %s |\n" total-time)))) total-time))))
(insert "|--|") (insert "|--|")
(org-table-align))) (org-table-align)))