From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: FYI: with-org-today-date macro, helps with testing Date: Sat, 29 Jul 2017 01:11:59 -0500 Message-ID: <87fudfepqo.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbKz0-0003rz-A3 for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 02:12:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbKyv-0002Ea-VP for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 02:12:14 -0400 Received: from [195.159.176.226] (port=37318 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dbKyv-0002E6-PG for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 02:12:09 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dbKym-00037p-3t for emacs-orgmode@gnu.org; Sat, 29 Jul 2017 08:12:00 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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.