In the attachments is a better version with tests that also addresses your latest critique.

On 13/08/2023 14.44, Ihor Radchenko wrote:
> Ihor Radchenko <yanta...@posteo.net> writes:
>
>>>               (while (or (= nshift 0)
>>> -                   (not (time-less-p nil time)))
>>> + (not (time-less-p nil (time-add time-to-extend time))))
>>
>> And this compares "now" with year 1970. Will always return nil.
>
> Hmm. I somehow missed `time-add'.
> However, this is still fishy.
> What if we have something like <2023-08-13 2:00 ++8h>?
> `org-extend-today-until' should probably be ignored then.
From 317ab3f132825af9e5caaf0dc1812df545f0ad5f Mon Sep 17 00:00:00 2001
From: Valentin Herrmann <m...@valentin-herrmann.de>
Date: Sun, 13 Aug 2023 09:48:42 +0200
Subject: [PATCH] org.el: Respect org-extend-today-until in timestamps with ++
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* org.el (org-auto-repeat-maybe): Changed org-auto-repeat-maybe, so that
switching a repeating todo with a timestamp of the form <… ++…> respects
`org-extend-today-until'.
---
 lisp/org.el              | 10 +++++++---
 testing/lisp/test-org.el | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index c037b3ee0..9c98d7538 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10111,9 +10111,13 @@ enough to shift date past today.  Continue? "
 			  (org-timestamp-change n (cdr (assoc what whata)))
 			  (org-in-regexp org-ts-regexp3)
 			  (setq ts (match-string 1))
-			  (setq time
-				(save-match-data
-				  (org-time-string-to-time ts)))))
+                          (setq time
+                                (save-match-data
+                                  (org-time-string-to-time ts)))
+                          (unless (equal what "h")
+                            (setq time
+                                  (time-add time
+                                            (seconds-to-time (* 3600 org-extend-today-until)))))))
 		      (org-timestamp-change (- n) (cdr (assoc what whata)))
 		      ;; Rematch, so that we have everything in place
 		      ;; for the real shift.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 1b00f6c45..0cf765af4 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -8390,6 +8390,39 @@ Paragraph<point>"
       (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
 	(org-todo "DONE")
 	(buffer-string)))))
+  ;; Handle `org-extend-today-until'.
+  (should
+   (string-match-p
+    "2014-03-04 .* 18:00"
+    (let ((org-extend-today-until 4))
+      (org-test-at-time "<2014-03-04 02:35>"
+        (org-test-with-temp-text "* TODO H\n<2014-03-02 18:00 ++1d>"
+	  (org-todo "DONE")
+	  (buffer-string))))))
+  (should
+   (string-match-p
+    "2014-03-04 .* 10:00"
+    (let ((org-extend-today-until 4))
+      (org-test-at-time "<2014-03-04 02:35>"
+        (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
+	  (org-todo "DONE")
+	  (buffer-string))))))
+  (should
+   (string-match-p
+    "2014-03-04 .* 18:00"
+    (let ((org-extend-today-until 4))
+      (org-test-at-time "<2014-03-04 02:35>"
+        (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+1d>"
+	  (org-todo "DONE")
+	  (buffer-string))))))
+  (should
+   (string-match-p
+    "2014-03-04 .* 10:35"
+    (let ((org-extend-today-until 4))
+      (org-test-at-time "<2014-03-04 02:35>"
+        (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
+	  (org-todo "DONE")
+	  (buffer-string))))))
   ;; Do not repeat inactive time stamps with a repeater.
   (should-not
    (string-match-p
-- 
2.40.1

Reply via email to