emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Capture with date prompt defaults to yesterday
@ 2019-05-19 13:36 Neil Jerram
  2019-05-28 20:20 ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2019-05-19 13:36 UTC (permalink / raw)
  To: Org Mode List

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

I have a capture template like this:

 '(org-capture-templates
   (quote
    (("a" "" entry
      (file "~/org/capture.org")
      "** TODO %?
SCHEDULED: %^t"))))

When I use that, the date prompt defaults to yesterday, whereas I'd expect
it to default to today.

I believe this is because I also have (setq org-extend-today-until 2).
What happens is that (org-get-cursor-date) gets the right _date_, then
converts that to a time at midnight, i.e. <date> 00:00.  And then, I
presume, some following code thinks that means <date>-1, because of my
org-extend-today-until setting.

Thoughts?

Many thanks,
   Neil

[-- Attachment #2: Type: text/html, Size: 1002 bytes --]

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

* Re: Capture with date prompt defaults to yesterday
  2019-05-19 13:36 Capture with date prompt defaults to yesterday Neil Jerram
@ 2019-05-28 20:20 ` Neil Jerram
  2019-06-07 12:33   ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2019-05-28 20:20 UTC (permalink / raw)
  To: Org Mode List


[-- Attachment #1.1: Type: text/plain, Size: 827 bytes --]

On Sun, 19 May 2019 at 14:36, Neil Jerram <neiljerram@gmail.com> wrote:

> I have a capture template like this:
>
>  '(org-capture-templates
>    (quote
>     (("a" "" entry
>       (file "~/org/capture.org")
>       "** TODO %?
> SCHEDULED: %^t"))))
>
> When I use that, the date prompt defaults to yesterday, whereas I'd expect
> it to default to today.
>
> I believe this is because I also have (setq org-extend-today-until 2).
> What happens is that (org-get-cursor-date) gets the right _date_, then
> converts that to a time at midnight, i.e. <date> 00:00.  And then, I
> presume, some following code thinks that means <date>-1, because of my
> org-extend-today-until setting.
>
> Thoughts?
>
> Many thanks,
>    Neil
>

Well I think it's a bug and propose the attached fix.  Please let me know
what you think.

     Neil

[-- Attachment #1.2: Type: text/html, Size: 1504 bytes --]

[-- Attachment #2: 0001-Make-capture-s-idea-of-the-current-day-more-intuitiv.patch --]
[-- Type: text/x-patch, Size: 1665 bytes --]

From d52c66f4e4f1fead135427d2c638890b5c7ab224 Mon Sep 17 00:00:00 2001
From: Neil Jerram <neil@tigera.io>
Date: Tue, 28 May 2019 21:01:17 +0100
Subject: [PATCH] Make capture's idea of the current day more intuitive

---
 lisp/org.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index c6861dc9a..763eb1e45 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18936,7 +18936,9 @@ Returns the number of empty lines passed."
 This works in the calendar and in the agenda, anywhere else it just
 returns the current time.
 If WITH-TIME is non-nil, returns the time of the event at point (in
-the agenda) or the current time of the day."
+the agenda) or the current time of the day; otherwise returns 12pm
+on the cursor date.  (Returning 12pm instead of 12am here avoids
+problems of interpretation with respect to `org-extend-today-until'.)"
   (let (date day defd tp hod mod)
     (when with-time
       (setq tp (get-text-property (point) 'time))
@@ -18949,13 +18951,13 @@ the agenda) or the current time of the day."
     (cond
      ((eq major-mode 'calendar-mode)
       (setq date (calendar-cursor-to-date)
-	    defd (encode-time 0 (or mod 0) (or hod 0)
+	    defd (encode-time 0 (or mod 0) (or hod 12)
 			      (nth 1 date) (nth 0 date) (nth 2 date))))
      ((eq major-mode 'org-agenda-mode)
       (setq day (get-text-property (point) 'day))
       (when day
 	(setq date (calendar-gregorian-from-absolute day)
-	      defd (encode-time 0 (or mod 0) (or hod 0)
+	      defd (encode-time 0 (or mod 0) (or hod 12)
 				(nth 1 date) (nth 0 date) (nth 2 date))))))
     (or defd (current-time))))
 
-- 
2.17.1


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

* Re: Capture with date prompt defaults to yesterday
  2019-05-28 20:20 ` Neil Jerram
@ 2019-06-07 12:33   ` Neil Jerram
  2019-06-07 21:31     ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2019-06-07 12:33 UTC (permalink / raw)
  To: Org Mode List

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

Nicolas, I hope you don't mind me sending a 'ping' for this, as it looks
like it might have got lost.  Please do let me know what you think.

Best wishes,
   Neil


On Tue, 28 May 2019 at 21:20, Neil Jerram <neiljerram@gmail.com> wrote:

> On Sun, 19 May 2019 at 14:36, Neil Jerram <neiljerram@gmail.com> wrote:
>
>> I have a capture template like this:
>>
>>  '(org-capture-templates
>>    (quote
>>     (("a" "" entry
>>       (file "~/org/capture.org")
>>       "** TODO %?
>> SCHEDULED: %^t"))))
>>
>> When I use that, the date prompt defaults to yesterday, whereas I'd
>> expect it to default to today.
>>
>> I believe this is because I also have (setq org-extend-today-until 2).
>> What happens is that (org-get-cursor-date) gets the right _date_, then
>> converts that to a time at midnight, i.e. <date> 00:00.  And then, I
>> presume, some following code thinks that means <date>-1, because of my
>> org-extend-today-until setting.
>>
>> Thoughts?
>>
>> Many thanks,
>>    Neil
>>
>
> Well I think it's a bug and propose the attached fix.  Please let me know
> what you think.
>
>      Neil
>
>

[-- Attachment #2: Type: text/html, Size: 2102 bytes --]

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

* Re: Capture with date prompt defaults to yesterday
  2019-06-07 12:33   ` Neil Jerram
@ 2019-06-07 21:31     ` Nicolas Goaziou
  2019-06-09 10:40       ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2019-06-07 21:31 UTC (permalink / raw)
  To: Neil Jerram; +Cc: Org Mode List

Hello,

Neil Jerram <neiljerram@gmail.com> writes:

> Nicolas, I hope you don't mind me sending a 'ping' for this, as it looks
> like it might have got lost.  Please do let me know what you think.

I'm not sure this is a right fix. Doesn't it force default times to noon
instead of midnight? I think default times should be midnight.

So the fix probably lies elsewhere. (Also, not the "important" section
in `org-extend-today-until').

Regards,

-- 
Nicolas Goaziou

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

* Re: Capture with date prompt defaults to yesterday
  2019-06-07 21:31     ` Nicolas Goaziou
@ 2019-06-09 10:40       ` Neil Jerram
  2019-06-10  9:22         ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Neil Jerram @ 2019-06-09 10:40 UTC (permalink / raw)
  To: Neil Jerram, Org Mode List


[-- Attachment #1.1: Type: text/plain, Size: 1057 bytes --]

On Fri, 7 Jun 2019 at 22:31, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Neil Jerram <neiljerram@gmail.com> writes:
>
> > Nicolas, I hope you don't mind me sending a 'ping' for this, as it looks
> > like it might have got lost.  Please do let me know what you think.
>
> I'm not sure this is a right fix. Doesn't it force default times to noon
> instead of midnight? I think default times should be midnight.
>

Yes, it does make the default time noon.  But AFAICS the time of day
doesn't actually matter in any of the Org source code where the result of
org-get-cursor-date is used.  Have I missed a case where it does matter?

However, in the attached patch I've revised that so that the default time
of day is <org-extend-today-until>:00am, i.e. it's the earliest time that
Org treats as being that date.  WDYT?

Alternatively, we could refactor the code around where org-get-cursor-date
is used to make it more explicit when the time of day doesn't matter, and
look further if there are any cases where it does.

Best wishes,
    Neil

[-- Attachment #1.2: Type: text/html, Size: 1582 bytes --]

[-- Attachment #2: 0001-Make-capture-s-idea-of-the-current-day-more-intuitiv.patch --]
[-- Type: text/x-patch, Size: 1675 bytes --]

From 48b342bbd8c97bf24214b57e04d6d59108320ba0 Mon Sep 17 00:00:00 2001
From: Neil Jerram <neil@tigera.io>
Date: Tue, 28 May 2019 21:01:17 +0100
Subject: [PATCH] Make capture's idea of the current day more intuitive

---
 lisp/org.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index c6861dc9a..6af97b348 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18936,7 +18936,9 @@ Returns the number of empty lines passed."
 This works in the calendar and in the agenda, anywhere else it just
 returns the current time.
 If WITH-TIME is non-nil, returns the time of the event at point (in
-the agenda) or the current time of the day."
+the agenda) or the current time of the day; otherwise returns the
+earliest time on the cursor date that Org treats as that date
+(bearing in mind `org-extend-today-until')."
   (let (date day defd tp hod mod)
     (when with-time
       (setq tp (get-text-property (point) 'time))
@@ -18949,13 +18951,13 @@ the agenda) or the current time of the day."
     (cond
      ((eq major-mode 'calendar-mode)
       (setq date (calendar-cursor-to-date)
-	    defd (encode-time 0 (or mod 0) (or hod 0)
+	    defd (encode-time 0 (or mod 0) (or hod org-extend-today-until)
 			      (nth 1 date) (nth 0 date) (nth 2 date))))
      ((eq major-mode 'org-agenda-mode)
       (setq day (get-text-property (point) 'day))
       (when day
 	(setq date (calendar-gregorian-from-absolute day)
-	      defd (encode-time 0 (or mod 0) (or hod 0)
+	      defd (encode-time 0 (or mod 0) (or hod org-extend-today-until)
 				(nth 1 date) (nth 0 date) (nth 2 date))))))
     (or defd (current-time))))
 
-- 
2.17.1


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

* Re: Capture with date prompt defaults to yesterday
  2019-06-09 10:40       ` Neil Jerram
@ 2019-06-10  9:22         ` Nicolas Goaziou
  2019-06-11  8:53           ` Neil Jerram
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2019-06-10  9:22 UTC (permalink / raw)
  To: Neil Jerram; +Cc: Org Mode List

Hello,

Neil Jerram <neiljerram@gmail.com> writes:

> Yes, it does make the default time noon.  But AFAICS the time of day
> doesn't actually matter in any of the Org source code where the result of
> org-get-cursor-date is used.  Have I missed a case where it does
> matter?

Probably not. I didn't check. But this could become a future gotcha.

> However, in the attached patch I've revised that so that the default time
> of day is <org-extend-today-until>:00am, i.e. it's the earliest time that
> Org treats as being that date.  WDYT?

I think this is better. I applied your patch. Thank you.

> Alternatively, we could refactor the code around where org-get-cursor-date
> is used to make it more explicit when the time of day doesn't matter, and
> look further if there are any cases where it does.

I think the current state is sufficient.

Regards,

-- 
Nicolas Goaziou

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

* Re: Capture with date prompt defaults to yesterday
  2019-06-10  9:22         ` Nicolas Goaziou
@ 2019-06-11  8:53           ` Neil Jerram
  0 siblings, 0 replies; 7+ messages in thread
From: Neil Jerram @ 2019-06-11  8:53 UTC (permalink / raw)
  To: Neil Jerram, Org Mode List

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

On Mon, 10 Jun 2019, 10:22 Nicolas Goaziou, <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Neil Jerram <neiljerram@gmail.com> writes:
>
> > Yes, it does make the default time noon.  But AFAICS the time of day
> > doesn't actually matter in any of the Org source code where the result of
> > org-get-cursor-date is used.  Have I missed a case where it does
> > matter?
>
> Probably not. I didn't check. But this could become a future gotcha.
>
> > However, in the attached patch I've revised that so that the default time
> > of day is <org-extend-today-until>:00am, i.e. it's the earliest time that
> > Org treats as being that date.  WDYT?
>
> I think this is better. I applied your patch. Thank you.
>
> > Alternatively, we could refactor the code around where
> org-get-cursor-date
> > is used to make it more explicit when the time of day doesn't matter, and
> > look further if there are any cases where it does.
>
> I think the current state is sufficient.
>
> Regards,
>
> --
> Nicolas Goaziou
>

Thanks Nicolas!
       Neil

[-- Attachment #2: Type: text/html, Size: 1796 bytes --]

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

end of thread, other threads:[~2019-06-11  8:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-19 13:36 Capture with date prompt defaults to yesterday Neil Jerram
2019-05-28 20:20 ` Neil Jerram
2019-06-07 12:33   ` Neil Jerram
2019-06-07 21:31     ` Nicolas Goaziou
2019-06-09 10:40       ` Neil Jerram
2019-06-10  9:22         ` Nicolas Goaziou
2019-06-11  8:53           ` Neil Jerram

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