emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: org-capture-templates with %^t
@ 2017-10-03 23:21 Matt Lundin
  2017-10-05 14:43 ` Matt Lundin
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lundin @ 2017-10-03 23:21 UTC (permalink / raw)
  To: Org Mode

After commit 51b431d01365211d4c40b07729d5d11d82b9dfe2,
org-capture-templates containing %^t do not work as expected.

The relevant capture template snippet looks like this:

(setq org-capture-templates
      '(("a" "Appointment" entry (file "~/inbox.org") "* %^{Appt}\n %^t%?\n %U\n
%a\n\n %i")))

With this capture template, I am prompted to enter a time via
org-read-date. The expected behavior is as follows:

 - if I enter a date and time of day, the resulting timestamp should 
   contain the time of day:
     - i.e., entering "Thu 8am" should yield "<2017-10-05 Thu 08:00>"
 - if I enter only a date, the resulting timestamp should contain a date
   with no time of day
 - if I enter nothing at the prompt, the resulting timestamp should
   contain today's date with no time of day

What happens now:

 - when I enter a date with a time of day, the timestamp is truncated
   and contains only a date
     - I.e., entering "Thu 8am" now yields "<2017-10-05 Thu>"

This, I think, is counter to the intent of the difference between %^t
and %^T. The lowercase and uppercase (time of day vs. no time of day)
should apply only to the default entry when nothing is entered. But when
the user enters information at the prompt, the behavior should be the
same as that of org-time-stamp, allowing a flexible decision on the fly
as to whether to enter a time of day.

Best,
Matt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: org-capture-templates with %^t
  2017-10-03 23:21 Bug: org-capture-templates with %^t Matt Lundin
@ 2017-10-05 14:43 ` Matt Lundin
  2017-10-06 15:20   ` Matt Lundin
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lundin @ 2017-10-05 14:43 UTC (permalink / raw)
  To: Org Mode

Matt Lundin <mdl@imapmail.org> writes:

> After commit 51b431d01365211d4c40b07729d5d11d82b9dfe2,
> org-capture-templates containing %^t do not work as expected.
>
> The relevant capture template snippet looks like this:
>
> (setq org-capture-templates
>       '(("a" "Appointment" entry (file "~/inbox.org") "* %^{Appt}\n %^t%?\n %U\n
> %a\n\n %i")))
>
> With this capture template, I am prompted to enter a time via
> org-read-date. The expected behavior is as follows:
>
>  - if I enter a date and time of day, the resulting timestamp should 
>    contain the time of day:
>      - i.e., entering "Thu 8am" should yield "<2017-10-05 Thu 08:00>"
>
> What happens now:
>
>  - when I enter a date with a time of day, the timestamp is truncated
>    and contains only a date
>      - I.e., entering "Thu 8am" now yields "<2017-10-05 Thu>"
>

There is a further bug here. With the capture template above, if I enter
a time range - i.e., an end time - the timestamp in the capture buffer
is incorrect.

Entering... "Thu 8am-10am" yields...

 <2017-10-05 Thu-10:00>

Best,
Matt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bug: org-capture-templates with %^t
  2017-10-05 14:43 ` Matt Lundin
@ 2017-10-06 15:20   ` Matt Lundin
  2017-10-06 17:15     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lundin @ 2017-10-06 15:20 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]

Matt Lundin <mdl@imapmail.org> writes:

> Matt Lundin <mdl@imapmail.org> writes:
>
>> After commit 51b431d01365211d4c40b07729d5d11d82b9dfe2,
>> org-capture-templates containing %^t do not work as expected.
>>
>> With this capture template, I am prompted to enter a time via
>> org-read-date. The expected behavior is as follows:
>>
>>  - if I enter a date and time of day, the resulting timestamp should 
>>    contain the time of day:
>>      - i.e., entering "Thu 8am" should yield "<2017-10-05 Thu 08:00>"
>>
>> What happens now:
>>
>>  - when I enter a date with a time of day, the timestamp is truncated
>>    and contains only a date
>>      - I.e., entering "Thu 8am" now yields "<2017-10-05 Thu>"
>>
>
> There is a further bug here. With the capture template above, if I enter
> a time range - i.e., an end time - the timestamp in the capture buffer
> is incorrect.
>
> Entering... "Thu 8am-10am" yields...
>
>  <2017-10-05 Thu-10:00>
>

Attached please find a patch that fixes these issues. It is a simple
change, but it brings the behavior of %^t and %^u vs. %^T and %^U into
line with the behavior of the interactive function org-time-stamp
without and with a prefix argument.

The escapes %^t and %^u now default to no time of day if the user enters
nothing but allow the optional entry of a time of day via user
interaction.

The escapes %^T and %^U always include a time of day, with or without
user interaction.

Best,
Matt


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-interactive-timestamp-entry-in-capture-templates.patch --]
[-- Type: text/x-diff, Size: 1500 bytes --]

From b3e9fc879c8cadd8b634d7f4f3512ba1eaf1b8bf Mon Sep 17 00:00:00 2001
From: Matt Lundin <mdl@imapmail.org>
Date: Fri, 6 Oct 2017 09:50:05 -0500
Subject: [PATCH] Fix interactive timestamp entry in capture templates

* lisp/org-capture.el: (org-capture-fill-template) Fix interactive
  timestamp entry to match the behavior of org-time-stamp. This fixes
  a bug related to the %^t and %^u template escapes which resulted in
  incorrect timestamps (<2017-10-06 Fri-12:00>). The difference
  between %^t and %^T now corresponds to the difference between
  org-time-stamp called without and with a prefix argument.
---
 lisp/org-capture.el | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 862cdb276..25af674b8 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1792,11 +1792,10 @@ The template may still contain \"%?\" for cursor positioning."
 		     (let* ((upcase? (equal (upcase key) key))
 			    (org-end-time-was-given nil)
 			    (time (org-read-date upcase? t nil prompt)))
-		       (let ((org-time-was-given upcase?))
-			 (org-insert-time-stamp
-			  time org-time-was-given
-			  (member key '("u" "U"))
-			  nil nil (list org-end-time-was-given)))))
+		       (org-insert-time-stamp
+			time (or org-time-was-given upcase?)
+			(member key '("u" "U"))
+			nil nil (list org-end-time-was-given))))
 		    (`nil
 		     (push (org-completing-read
 			    (concat (or prompt "Enter string")
-- 
2.14.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: Bug: org-capture-templates with %^t
  2017-10-06 15:20   ` Matt Lundin
@ 2017-10-06 17:15     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2017-10-06 17:15 UTC (permalink / raw)
  To: Org Mode

Hello,

Matt Lundin <mdl@imapmail.org> writes:

> Attached please find a patch that fixes these issues. It is a simple
> change, but it brings the behavior of %^t and %^u vs. %^T and %^U into
> line with the behavior of the interactive function org-time-stamp
> without and with a prefix argument.
>
> The escapes %^t and %^u now default to no time of day if the user enters
> nothing but allow the optional entry of a time of day via user
> interaction.
>
> The escapes %^T and %^U always include a time of day, with or without
> user interaction.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-10-06 17:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 23:21 Bug: org-capture-templates with %^t Matt Lundin
2017-10-05 14:43 ` Matt Lundin
2017-10-06 15:20   ` Matt Lundin
2017-10-06 17:15     ` Nicolas Goaziou

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).