Hi all, I ran into a subtle bug yesterday. Basically, when using org-capture to capture
- an entry into a datetree, - on a date other than today (using :time-prompt in org-capture-templates) - with a capture template that inserts a timestamp (%T) then I get incorrect results for either the timestamp or the location in the datetree, depending on how I enter the date. Here is a minimal working example: #+begin_src emacs-lisp (setq org-capture-templates `( ("d" "Diary") ("da" "Appointment/Event" entry (file+olp+datetree "/tmp/diary.org") "**** %^{Description}\n %T" :time-prompt t))) #+end_src Notice that the template contains %T, to expand to a timestamp with a time, and also that the capture target is a datetree and :time-prompt is true. My understanding is that this should both file the entry to the entered date in the datetree, and fill the %T template with a timestamp for the entered date (and time, if any). Here are the results from running a few captures with this setup on Dec 24 around 11AM. I tried various ways of scheduling an event on Dec 31 at 13:00; what I entered into the prompt of org-read-date is shown in the headline: #+begin_example * 2020 ** 2020-12 December *** 2020-12-24 Thursday **** Entered "31-12" <2020-12-31 Thu 11:06> This gets filed to the wrong day in the datetree, but the date in the timestamp is correct. The time is also correct (it's the current time, since no time was entered). **** Entered "31-12 13:00" <2020-12-31 Thu 13:00> This gets filed to the wrong day in the datetree, but the date and time in the timestamp are correct. *** 2020-12-31 Thursday **** Entered "12-31" <2020-12-31 Thu 00:00> This gets filed to the correct day in the datetree and the date in the timestamp is correct. The time is 00:00 because no time was entered. (Why isn't the time 11:06, though, like in the first example?) **** Entered "12-31 13:00" <2021-01-12 Tue 13:00> This is the most problematic case: it gets filed to the correct day in the datetree, but the date in the timestamp is incorrect! **** Entered "2020-12-31 13:00" <2020-12-31 Thu 13:00> If I enter the date in full ISO format, the location in the datetree and the timestamp are both correct. #+end_example Possibly relevant here is the value of calendar-date-style, which is 'american for me. I tested briefly with 'european but it did not make a difference for the "31-12" cases. This is org 9.4 running from maint (commit ab00524fc). I spent a while stepping through org-capture and org-read-date but haven't found the problem yet. I suspect this snippet from a cond form in the middle of org-capture-set-target-location: #+begin_src ((string-match "\\([^ ]+\\)-[^ ]+[ ]+\\(.*\\)" org-read-date-final-answer) ;; Replace any time range by its start. (apply #'encode-time (org-read-date-analyze ;; it looks to me like this is maybe sending the wrong value ;; into org-read-date-analyze: (replace-match "\\1 \\2" nil nil org-read-date-final-answer) #+end_src Will report here if I find out more exactly. Happy holidays, everyone! -- Best, Richard