From: Kyle Meyer <kyle@kyleam.com>
To: emacs-orgmode@gnu.org
Cc: jhenahan@me.com
Subject: [PATCH 1/2] org-clock: Simplify `untilnow' range logic
Date: Fri, 28 Dec 2018 16:42:49 -0500 [thread overview]
Message-ID: <20181228214250.800-1-kyle@kyleam.com> (raw)
In-Reply-To: <20181228213627.387-1-kyle@kyleam.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'.
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
next prev parent reply other threads:[~2018-12-28 21:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-28 21:36 [PATCH 0/2] org-clock: Simplify `untilnow' range logic Kyle Meyer
2018-12-28 21:42 ` Kyle Meyer [this message]
2018-12-28 21:42 ` [PATCH 2/2] org-parse-time-string: Describe time stamp matching behavior Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181228214250.800-1-kyle@kyleam.com \
--to=kyle@kyleam.com \
--cc=emacs-orgmode@gnu.org \
--cc=jhenahan@me.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).