Use higher level helpers instead of `encode-time'

* lisp/org-clock.el (org-clock-sum)
(org-clock-update-time-maybe):
Prefer org-time-string-to-seconds to doing it by hand.
* lisp/org-macs.el (org-2ft):
Prefer org-time-string-to-seconds to doing it by hand.
* lisp/org-table.el (org-table-eval-formula):
Prefer org-time-string-to-time to doing it by hand.

Max Nikulin:
A larger patch "Improve Org usage of timestamps" was suggested in
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=54764#10

Only cosmetic changes are selected for this patch.
This commit is contained in:
Paul Eggert 2022-04-09 00:17:09 -07:00 committed by Ihor Radchenko
parent a189697681
commit a4105d0942
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 8 additions and 14 deletions

View File

@ -1914,13 +1914,10 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(cond
((match-end 2)
;; Two time stamps.
(let* ((ts (float-time
(apply #'encode-time
(save-match-data
(org-parse-time-string (match-string 2))))))
(te (float-time
(apply #'encode-time
(org-parse-time-string (match-string 3)))))
(let* ((ss (match-string 2))
(se (match-string 3))
(ts (org-time-string-to-seconds ss))
(te (org-time-string-to-seconds se))
(dt (- (if tend (min te tend) te)
(if tstart (max ts tstart) ts))))
(when (> dt 0) (cl-incf t1 (floor dt 60)))))
@ -3052,10 +3049,8 @@ Otherwise, return nil."
(end-of-line 1)
(setq ts (match-string 1)
te (match-string 3))
(setq s (- (float-time
(apply #'encode-time (org-parse-time-string te)))
(float-time
(apply #'encode-time (org-parse-time-string ts))))
(setq s (- (org-time-string-to-seconds te)
(org-time-string-to-seconds ts))
neg (< s 0)
s (abs s)
h (floor (/ s 3600))

View File

@ -1358,7 +1358,7 @@ nil, just return 0."
((numberp s) s)
((stringp s)
(condition-case nil
(float-time (apply #'encode-time (org-parse-time-string s)))
(org-time-string-to-seconds s)
(error 0)))
(t 0)))

View File

@ -2607,8 +2607,7 @@ location of point."
(format-time-string
(org-time-stamp-format
(string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}" ts))
(apply #'encode-time
(save-match-data (org-parse-time-string ts))))))
(save-match-data (org-time-string-to-time ts)))))
form t t))
(setq ev (if (and duration (string-match "^[0-9]+:[0-9]+\\(?::[0-9]+\\)?$" form))