From 70d6341f2e4cec845d6ff2925f8b6c73dfddffa7 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 1 Jan 2010 11:31:57 +0100 Subject: [PATCH] Improve future detection when reading dates PT writes: > [Orgmode] org-read-date-prefer-future 'time doesn't always prefer future > > This is a very useful setting, because it allows the user to > quickly schedule a task into the future by simply entering the > time, but it doesn't always do the right thing. > > Suppose I scheduled a task to 1pm, but I didn't have time to deal > with it during the day. It's 5pm now. If I want to reschedule the task to > tomorrow 10am then I can write simply 10am to the time prompt and > it puts the task correctly to tomorrow 10am. However, if I want > to reschedule it to tomorrow 2pm then I can't write simply 2pm, > because then it schedules the task at 2pm today (which is past > already, since it's 5 pm). > > The problem is the feature uses the task's own scheduled time to > determine if a time is in the past, instead of the current time. > > > It's Org-mode version 6.33 --- lisp/ChangeLog | 2 ++ lisp/org.el | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d1db56dc2..3cd5e1287 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -7,6 +7,8 @@ variables on which image creation depends. (org-create-formula-image): Add the header stuff from in-buffer settings. + (org-read-date-analyze): Base the analysis for future preference + on NOW, not on the default date. * org-inlinetask.el (org-inlinetask-export-handler): Add CSS class for TODO keyword in inline tasks. diff --git a/lisp/org.el b/lisp/org.el index 19884f3d1..2fe62c23e 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -13342,9 +13342,10 @@ user." (defun org-read-date-analyze (ans def defdecode) "Analyse the combined answer of the date prompt." ;; FIXME: cleanup and comment - (let (delta deltan deltaw deltadef year month day - hour minute second wday pm h2 m2 tl wday1 - iso-year iso-weekday iso-week iso-year iso-date futurep) + (let ((nowdecode (decode-time (current-time))) + delta deltan deltaw deltadef year month day + hour minute second wday pm h2 m2 tl wday1 + iso-year iso-weekday iso-week iso-year iso-date futurep) (setq org-read-date-analyze-futurep nil) (when (string-match "\\`[ \t]*\\.[ \t]*\\'" ans) (setq ans "+0")) @@ -13417,13 +13418,13 @@ user." day (or (nth 3 tl) (nth 3 defdecode)) month (or (nth 4 tl) (if (and org-read-date-prefer-future - (nth 3 tl) (< (nth 3 tl) (nth 3 defdecode))) - (prog1 (1+ (nth 4 defdecode)) (setq futurep t)) + (nth 3 tl) (< (nth 3 tl) (nth 3 nowdecode))) + (prog1 (1+ (nth 4 nowdecode)) (setq futurep t)) (nth 4 defdecode))) year (or (nth 5 tl) (if (and org-read-date-prefer-future - (nth 4 tl) (< (nth 4 tl) (nth 4 defdecode))) - (prog1 (1+ (nth 5 defdecode)) (setq futurep t)) + (nth 4 tl) (< (nth 4 tl) (nth 4 nowdecode))) + (prog1 (1+ (nth 5 nowdecode)) (setq futurep t)) (nth 5 defdecode))) hour (or (nth 2 tl) (nth 2 defdecode)) minute (or (nth 1 tl) (nth 1 defdecode)) @@ -13432,14 +13433,14 @@ user." (when (and (eq org-read-date-prefer-future 'time) (not (nth 3 tl)) (not (nth 4 tl)) (not (nth 5 tl)) - (equal day (nth 3 defdecode)) - (equal month (nth 4 defdecode)) - (equal year (nth 5 defdecode)) + (equal day (nth 3 nowdecode)) + (equal month (nth 4 nowdecode)) + (equal year (nth 5 nowdecode)) (nth 2 tl) - (or (< (nth 2 tl) (nth 2 defdecode)) - (and (= (nth 2 tl) (nth 2 defdecode)) + (or (< (nth 2 tl) (nth 2 nowdecode)) + (and (= (nth 2 tl) (nth 2 nowdecode)) (nth 1 tl) - (< (nth 1 tl) (nth 1 defdecode))))) + (< (nth 1 tl) (nth 1 nowdecode))))) (setq day (1+ day) futurep t))