From: Adam Porter <adam@alphapapa.net>
To: emacs-orgmode@gnu.org
Subject: FYI: with-org-today-date macro, helps with testing
Date: Sat, 29 Jul 2017 01:11:59 -0500 [thread overview]
Message-ID: <87fudfepqo.fsf@alphapapa.net> (raw)
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.
next reply other threads:[~2017-07-29 6:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-29 6:11 Adam Porter [this message]
2017-07-29 14:43 ` FYI: with-org-today-date macro, helps with testing Kyle Meyer
2017-07-29 19:44 ` Adam Porter
2017-07-29 20:26 ` Kyle Meyer
2017-07-29 23:03 ` Adam Porter
2018-10-23 20:56 ` Samuel Wales
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fudfepqo.fsf@alphapapa.net \
--to=adam@alphapapa.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.