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
This commit is contained in:
Ihor Radchenko 2023-02-22 13:19:06 +03:00
parent eea8da0315
commit 7a90f596d9
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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