From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id sPp+K1xDBmBSBgAA0tVLHw (envelope-from ) for ; Tue, 19 Jan 2021 02:26:36 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0m0cJ1xDBmCCeQAAbx9fmQ (envelope-from ) for ; Tue, 19 Jan 2021 02:26:36 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D35E99403D6 for ; Tue, 19 Jan 2021 02:26:33 +0000 (UTC) Received: from localhost ([::1]:42888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1gj2-0006If-RE for larch@yhetil.org; Mon, 18 Jan 2021 21:26:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1giF-00062D-93 for emacs-orgmode@gnu.org; Mon, 18 Jan 2021 21:25:43 -0500 Received: from out1.migadu.com ([2001:41d0:2:863f::]:51344) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1gi8-0002S2-JF for emacs-orgmode@gnu.org; Mon, 18 Jan 2021 21:25:41 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1611023130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=LLLdegXhkCia/+ldFkAn1/r1/o2NsAklcPEGXPXX+xU=; b=cFI0XZjotR3VQYS5awEpDlcVZ8+txxu3rbg+S0pCQRhnwDbLUsmYGFo2SiWSzjJfQIN5f3 jvCFEqtuEP4aJIVuUkMZKrL4ijd1igWHoPqyjNKa6vnpHox0BYywmeYGtsjCbS8/VqDY9E GHMMA2Xs2GwtPlvRE3gp5O7zmOg3ZiXCiiV72/XgWeSjt5J9GZKcZy6+OupAtT88bwnVaC FY4tK4hLt8luzom75WvszoQ8AxmfXbiaWL4/QFUPsrxDvBXRDLZN3+WKzzniwOyOl4pupJ Jc0yug5f1WePVYHNX0JYq3QfmuiWbpb2jlOgP90I12WZEfhlWT7gy84Vr6M4cg== From: Kyle Meyer To: Richard Lawrence Subject: [PATCH] capture: Fix handling of time range for :time-prompt In-Reply-To: <87o8hm3g6v.fsf@kyleam.com> Date: Mon, 18 Jan 2021 21:25:27 -0500 Message-ID: <878s8pll2g.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Auth-User: kyle@kyleam.com Received-SPF: pass client-ip=2001:41d0:2:863f::; envelope-from=kyle@kyleam.com; helo=out1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.55 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=kyleam.com header.s=key1 header.b=cFI0XZjo; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: D35E99403D6 X-Spam-Score: -2.55 X-Migadu-Scanner: scn0.migadu.com X-TUID: d6OI59QYFA/N Kyle Meyer writes: > I'm okay with the minimal fix to the regexp, though I wonder if we can > avoid the follow-up call to org-read-date-analyze entirely. I'm running > out of time to test thoroughly tonight, but perhaps something like this > (ignoring the potential cond->if cleanup): Testing that against the cases in your initial report, I believe it leads to the same results as your patch, so here's a cleaned-up version. -- >8 -- Subject: [PATCH] capture: Fix handling of time range for :time-prompt * lisp/org-capture.el (org-capture-set-target-location): Bind org-end-time-was-given around the org-read-date call to get a return value that uses the start time rather than doing custom adjustment of the return value. If org-capture-set-target-location detects that the answer to org-read-date has a time range, it strips the end time from the answer and calls org-read-date-analyze again. (org-read-date already calls it underneath.) The regexp it uses, however, can easily match a date, leading to a bogus result. org-read-date-analyze is already capable of processing the time range in a way that matches org-capture-set-target-location's intent: when org-end-time-was-given is bound, org-read-date-analyze splits off the end value of the range and stores it in org-end-time-was-given. Drop the custom logic and let org-read-date-analyze handle the range. Reported-by: Richard Lawrence Ref: https://orgmode.org/list/87h7obh4ct.fsf@aquinas --- lisp/org-capture.el | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index f40f2b335..d7b69f228 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1025,28 +1025,23 @@ (defun org-capture-set-target-location (&optional target) (time-to-days org-overriding-default-time)) ((or (org-capture-get :time-prompt) (equal current-prefix-arg 1)) - ;; Prompt for date. - (let ((prompt-time (org-read-date - nil t nil "Date for tree entry:"))) + ;; Prompt for date. Bind `org-end-time-was-given' so + ;; that `org-read-date-analyze' handles the time range + ;; case and returns `prompt-time' with the start value. + (let* ((org-time-was-given nil) + (org-end-time-was-given nil) + (prompt-time (org-read-date + nil t nil "Date for tree entry:"))) (org-capture-put :default-time - (cond ((and (or (not (boundp 'org-time-was-given)) - (not org-time-was-given)) - (not (= (time-to-days prompt-time) (org-today)))) - ;; Use 00:00 when no time is given for another - ;; date than today? - (apply #'encode-time 0 0 - org-extend-today-until - (cl-cdddr (decode-time prompt-time)))) - ((string-match "\\([^ ]+\\)-[^ ]+[ ]+\\(.*\\)" - org-read-date-final-answer) - ;; Replace any time range by its start. - (apply #'encode-time - (org-read-date-analyze - (replace-match "\\1 \\2" nil nil - org-read-date-final-answer) - prompt-time (decode-time prompt-time)))) - (t prompt-time))) + (if (and (or (not org-time-was-given)) + (not (= (time-to-days prompt-time) (org-today)))) + ;; Use 00:00 when no time is given for another + ;; date than today? + (apply #'encode-time 0 0 + org-extend-today-until + (cl-cdddr (decode-time prompt-time))) + prompt-time)) (time-to-days prompt-time))) (t ;; Current date, possibly corrected for late night base-commit: 9e8215f4a5df7d03ac787da78d28f69a4c18e7d3 -- 2.29.2