emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 1/2] org-clock: Simplify `untilnow' range logic


From: Kyle Meyer
Subject: [O] [PATCH 1/2] org-clock: Simplify `untilnow' range logic
Date: Fri, 28 Dec 2018 16:42:49 -0500

* lisp/org-clock.el (org-clock-special-range): Use nil to represent
`untilnow'.

For `untilnow', org-clock-special-range sets the start to
"<-50001-11-30 Tue 00:00>", but org-parse-time-string actually assumes
a YYYY-MM-DD format and parses the year as 0001.  By chance, this is
still a really old date, so no one noticed.  However, with the port of
Emacs's fde99c729c (Port recent org-clock fix to POSIX time_t,
2018-03-28), test-org-clock/clocktable/ranges would fail if the system
supports the oldest date tried, "<-67715-09-22 Tue 17:51>".

But this "encode-time -> format-time-string -> org-parse-time-string"
dance is unnecessary.  All the current callers of
org-clock-special-range in Org's codebase (1) explicitly check if the
starting time is nil, (2) don't use the starting time, or (3) pass it
directly to org-clock-sum, which handles nil values.  And
org-clock-sum executes the same codepath when nil is passed instead of
"really old date".
---
 lisp/org-clock.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 494423e4e..2c24b04fb 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2126,7 +2126,8 @@ (defun org-clock-special-range (key &optional time 
as-strings wstart mstart)
 the beginning of the range and one for its end, like the ones
 returned by `current-time' or `encode-time' and a string used to
 display information.  If AS-STRINGS is non-nil, the returned
-times will be formatted strings.
+times will be formatted strings.  Note that the first element is
+always nil when KEY is `untilnow'.
 
 If WSTART is non-nil, use this number to specify the starting day
 of a week (monday is 1).  If MSTART is non-nil, use this number
@@ -2243,9 +2244,7 @@ (defun org-clock-special-range (key &optional time 
as-strings wstart mstart)
     ;; Format start and end times according to AS-STRINGS.
     (let* ((start (pcase key
                    (`interactive (org-read-date nil t nil "Range start? "))
-                    ;; In theory, all clocks started after the dawn of
-                    ;; humanity.
-                   (`untilnow (encode-time 0 0 0 0 0 -50000))
+                   (`untilnow nil)
                    (_ (encode-time 0 m h d month y))))
           (end (pcase key
                  (`interactive (org-read-date nil t nil "Range end? "))
@@ -2269,7 +2268,7 @@ (defun org-clock-special-range (key &optional time 
as-strings wstart mstart)
              (`untilnow "now"))))
       (if (not as-strings) (list start end text)
        (let ((f (cdr org-time-stamp-formats)))
-         (list (format-time-string f start)
+         (list (and start (format-time-string f start))
                (format-time-string f end)
                text))))))
 
-- 
2.20.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]