emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* FYI: with-org-today-date macro, helps with testing
@ 2017-07-29  6:11 Adam Porter
  2017-07-29 14:43 ` Kyle Meyer
  0 siblings, 1 reply; 6+ messages in thread
From: Adam Porter @ 2017-07-29  6:11 UTC (permalink / raw)
  To: emacs-orgmode

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-23 20:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-29  6:11 FYI: with-org-today-date macro, helps with testing Adam Porter
2017-07-29 14:43 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).