spegoraro / org-alert

System notifications of org agenda items
GNU General Public License v3.0
278 stars 26 forks source link

Too greedy regex in org-alert-time-match-string #29

Closed hai5 closed 1 year ago

hai5 commented 1 year ago

Given an agenda tree such as

org-alert-check will detect "15:30" for the task's time instead of "07:00". This is due to the regex in org-alert-time-match-string being too greedy.

This could be fix by using non-greedy match regex like "\(?:SCHEDULED\|DEADLINE\):.?<.?\([0-9]\{2\}:[0-9]\{2\}\).*>" instead.

ntBre commented 1 year ago

Thanks for the suggestion! org-alert-time-match-string is exposed as a variable though, so you should be able to set it to whatever you want in your config. I think I'll leave the default alone for now, but I'll include this as an example in the readme when I get back to my computer since it might be a common case. I might even add it to the doc string itself.

hai5 commented 1 year ago

Sorry for the typo. I mean the fix should be "\\(?:SCHEDULED\\|DEADLINE\\):.*?<.*?\\([0-9]\\{2\\}:[0-9]\\{2\\}\\).*>"

wwhiffle commented 4 months ago

Sorry for the typo. I mean the fix should be "\(?:SCHEDULED\|DEADLINE\):.?<.?\([0-9]\{2\}:[0-9]\{2\}\).*>"

This is also effective for recurring tasks that require clocking in.

SCHEDULED: <2024-06-28 Fri 21:00 +1d>
:LOGBOOK:
CLOCK: [2024-06-28 Fri 15:05]--[2024-06-28 Fri 15:07] =>  0:02
:END:

Since => contains >, any "HH:MM" time format like "15:05" between SCHEDULED: < and => will be matched.

The regex \\(?:SCHEDULED\\|DEADLINE\\):.*?<.*?\\([0-9]\\{2\\}:[0-9]\\{2\\}\\).*> resolves this issue.

iftheshoefritz commented 3 months ago

This is also good for time ranges in scheduled items: SCHEDULED: <2024-07-12 Fri 09:30-09:45> where I want to receive a notification about the start of the time range and don't care about the end.