From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: [PATCH 1/2] org-clock: Simplify `untilnow' range logic Date: Fri, 28 Dec 2018 16:42:49 -0500 Message-ID: <20181228214250.800-1-kyle@kyleam.com> References: <20181228213627.387-1-kyle@kyleam.com> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gd06i-0003TI-C9 for emacs-orgmode@gnu.org; Fri, 28 Dec 2018 16:55:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gczuK-0001gh-D6 for emacs-orgmode@gnu.org; Fri, 28 Dec 2018 16:43:07 -0500 Received: from pb-smtp21.pobox.com ([173.228.157.53]:53919) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gczuK-0001fS-31 for emacs-orgmode@gnu.org; Fri, 28 Dec 2018 16:43:04 -0500 In-Reply-To: <20181228213627.387-1-kyle@kyleam.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: jhenahan@me.com * 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'. =20 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)))))) =20 --=20 2.20.0