branch: externals-release/org
commit 7a90f596d975a30edc744db7f6091ab49e27eb1f
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-clock-timestamps-change: Fix when on opening timestamp
    
    * lisp/org-clock.el (org-clock-timestamps-change): Do not rely on
    global `org-last-changed-timestamp'.
    *
    testing/lisp/test-org-clock.el (test-org-clok/org-clock-timestamps-change):
    Add new test.
    
    Reported-by: sting.startup...@icloud.com
    Link: 
https://orgmode.org/list/2380d54f-de06-4cbe-88ac-5906a6e92...@gmail.com
---
 lisp/org-clock.el              |  6 +++++-
 testing/lisp/test-org-clock.el | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 55372e5649..ca4dcd6204 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1798,7 +1798,11 @@ Optional argument N tells to change by that many units."
              (begts (if updatets1 begts1 begts2)))
          (setq tdiff
                (time-subtract
-                (org-time-string-to-time org-last-changed-timestamp)
+                (org-time-string-to-time
+                  (save-excursion
+                    (goto-char (if updatets1 begts2 begts1))
+                    (looking-at org-ts-regexp3)
+                    (match-string 0)))
                 (org-time-string-to-time ts)))
           ;; `save-excursion' won't work because
           ;; `org-timestamp-change' deletes and re-inserts the
diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 68286b1744..f732e471a3 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -89,6 +89,30 @@ the buffer."
     ;; Remove clocktable.
     (delete-region (point) (search-forward "#+END:\n"))))
 
+(ert-deftest test-org-clok/org-clock-timestamps-change ()
+  "Test `org-clock-timestamps-change' specifications."
+  (should
+   (equal
+    "CLOCK: [2023-02-19 Sun 21:30]--[2023-02-19 Sun 23:35] =>  2:05"
+    (org-test-with-temp-text
+        "CLOCK: [2023-02-19 Sun 2<point>2:30]--[2023-02-20 Mon 00:35] =>  2:05"
+      (org-clock-timestamps-change 'down 1)
+      (buffer-string))))
+  (should
+   (equal
+    "CLOCK: [2023-02-20 Mon 00:00]--[2023-02-20 Mon 00:40] =>  0:40"
+    (org-test-with-temp-text
+        "CLOCK: [2023-02-19 Sun 23:<point>55]--[2023-02-20 Mon 00:35] =>  0:40"
+      (org-clock-timestamps-change 'up 1)
+      (buffer-string))))
+  (should
+   (equal
+    "CLOCK: [2023-02-20 Mon 00:30]--[2023-02-20 Mon 01:35] =>  1:05"
+    (org-test-with-temp-text
+        "CLOCK: [2023-02-19 Sun 2<point>3:30]--[2023-02-20 Mon 00:35] =>  1:05"
+      (org-clock-timestamps-change 'up 1)
+      (buffer-string)))))
+
 
 ;;; Clock drawer
 

Reply via email to