From a582bd2efadbb88f79592efd31023c816a86a3ae Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 9 Apr 2022 00:17:09 -0700 Subject: [PATCH 3/7] 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. --- lisp/org-clock.el | 17 ++++++----------- lisp/org-macs.el | 2 +- lisp/org-table.el | 3 +-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index ec87aaf8a..9f80dea04 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -1913,13 +1913,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))))) @@ -3051,10 +3048,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)) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 241155064..435c9ea30 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -1355,7 +1355,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))) diff --git a/lisp/org-table.el b/lisp/org-table.el index 2f31bef56..40a425197 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -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)) -- 2.25.1