Skip to content

Commit

Permalink
Fix bug in alc-org-todo-custom-date
Browse files Browse the repository at this point in the history
  • Loading branch information
alecigne committed Jan 22, 2023
1 parent 49702f3 commit d012275
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lisp/alc/alc-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,29 @@ address."
,(concat "* Note (taken from %a)\n" "\n" "%?\n")
:kill-buffer t)))

;; TODO This doesn't set the correct date in the logbook.
;; Hacky combination of these SO answers:
;; - https://stackoverflow.com/a/28130043
;; - https://emacs.stackexchange.com/a/9451
(defun alc-org-todo-custom-date (&optional arg)
"Like org-todo-yesterday, but prompt the user for a date. The
time of change will be 23:59 on that day"
(interactive "P")
(let* ((hour (nth 2 (decode-time (org-current-time))))
(daysback (- (date-to-day (current-time-string))
(org-time-string-to-absolute (org-read-date))))
(org-extend-today-until (+ 1 (* 24 (- daysback 1)) hour))
(org-use-effective-time t)) ; use the adjusted timestamp for logging
(cl-flet ((end-of-day (time)
(encode-time
(cl-destructuring-bind (s mi h d mo y a b c) (decode-time time)
(list 59 59 23 d mo y)))))
(cl-letf* ((now (current-time))
(then (end-of-day (org-read-date nil t)))
(days-diff (- (time-to-days now) (time-to-days then)))
(hour (nth 2 (decode-time now)))
(org-extend-today-until (+ 1 (* 24 (- days-diff 1)) hour))
(org-use-effective-time t)
(org-read-date-prefer-future nil)
((symbol-function #'org-current-effective-time)
#'(lambda () then)))
(if (eq major-mode 'org-agenda-mode)
(org-agenda-todo arg)
(org-todo arg))))
(org-todo arg)))))

(setq alc-org-next-tag "next")

Expand Down

0 comments on commit d012275

Please sign in to comment.