From 7a90f596d975a30edc744db7f6091ab49e27eb1f Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 22 Feb 2023 13:19:06 +0300 Subject: [PATCH] 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-0y@icloud.com Link: https://orgmode.org/list/2380D54F-DE06-4CBE-88AC-5906A6E9253A@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 55372e564..ca4dcd620 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 68286b174..f732e471a 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 22: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: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 23:30]--[2023-02-20 Mon 00:35] => 1:05" + (org-clock-timestamps-change 'up 1) + (buffer-string))))) + ;;; Clock drawer