From 4953e495b938011582fb0c7c7bf9064530ce9294 Mon Sep 17 00:00:00 2001 From: Don March Date: Wed, 1 Jun 2016 00:05:12 -0400 Subject: [PATCH 1/2] Make today's deadlines "close" without lead time * lisp/org.el (org-deadline-close): A timestamp is close if the days between now and the timestamp are less then or equal to the days of lead time. * testing/lisp/test-org.el: Add tests for org-deadline-close. --- lisp/org.el | 2 +- testing/lisp/test-org.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index e015a77..13883c5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -17480,7 +17480,7 @@ If SECONDS is non-nil, return the difference in seconds." (defun org-deadline-close (timestamp-string &optional ndays) "Is the time in TIMESTAMP-STRING close to the current date?" (setq ndays (or ndays (org-get-wdays timestamp-string))) - (and (< (org-time-stamp-to-now timestamp-string) ndays) + (and (<= (org-time-stamp-to-now timestamp-string) ndays) (not (org-entry-is-done-p)))) (defun org-get-wdays (ts &optional delay zero-delay) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 6884c24..576402a 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -364,6 +364,34 @@ (calendar-gregorian-from-absolute (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future))))) +(ert-deftest test-org/deadline-close () + "Test `org-deadline-close' specifications." + ;; Pretend that the current time is 2016-06-03 Fri 01:43 + (cl-flet ((current-time () '(22353 6425 905205 644000))) + ;; Timestamps are close if they are within `ndays' of lead time. + (org-test-with-temp-text "* Heading" + (should (org-deadline-close "2016-06-03 Fri" 0)) + (should (org-deadline-close "2016-06-02 Thu" 0)) + (should-not (org-deadline-close "2016-06-04 Sat" 0)) + (should (org-deadline-close "2016-06-04 Sat" 1)) + (should (org-deadline-close "2016-06-03 Fri 12:00" 0))) + ;; Read `ndays' from timestamp if argument not given. + (org-test-with-temp-text "* H" + (should (org-deadline-close "2016-06-04 Sat -1d")) + (should-not (org-deadline-close "2016-06-04 Sat -0d")) + (should (org-deadline-close "2016-06-10 Fri -1w")) + (should-not (org-deadline-close "2016-06-11 Sat -1w"))) + ;; Prefer `ndays' argument over lead time in timestamp. + (org-test-with-temp-text "* H" + (should (org-deadline-close "2016-06-04 Sat -0d" 1)) + (should-not (org-deadline-close "2016-06-04 Sat -0d" 0))) + ;; Completed tasks are never close. + (let ((org-todo-keywords '(("TODO" "|" "DONE")))) + (org-test-with-temp-text "* TODO Heading" + (should (org-deadline-close "2016-06-03"))) + (org-test-with-temp-text "* DONE Heading" + (should-not (org-deadline-close "2016-06-03")))))) + ;;; Drawers -- 2.8.1