[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] FYI: with-org-today-date macro, helps with testing
From: |
Adam Porter |
Subject: |
[O] FYI: with-org-today-date macro, helps with testing |
Date: |
Sat, 29 Jul 2017 01:11:59 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
Hi friends,
Just wanted to drop this here. I was testing some agenda-related code,
and got tired of having to keep moving the dates forward on my test data
as days passed in real life, so after digging into the agenda code, I
came up with this macro that makes testing much easier:
#+BEGIN_SRC elisp
(defmacro with-org-today-date (date &rest body)
"Run BODY with the `org-today' function set to return simply DATE.
DATE should be a date-time string (both date and time must be included)."
(declare (indent defun))
`(let ((day (date-to-day ,date))
(orig (symbol-function 'org-today)))
(unwind-protect
(progn
(fset 'org-today (lambda () day))
,@body)
(fset 'org-today orig))))
#+END_SRC
You can use it like this:
#+BEGIN_SRC elisp
(with-org-today-date "2017-07-05 00:00"
(let ((org-agenda-files (list "~/test.org"))
(org-agenda-span 'day))
(org-agenda-list nil)))
#+END_SRC
Hope someone finds this useful.
- [O] FYI: with-org-today-date macro, helps with testing,
Adam Porter <=