Browse Source

org-macs: Allow specifying relative time in hours

* lisp/org-macs.el (org-matcher-time): Handle hour ("h") time stamp
modifier.
* doc/org-manual.org (The date/time prompt): Document hour modifier.

This adds support for date expressions such as +12h to
org-matcher-time. The regexp this function uses to parse such relative
expressions already includes the "h" character but doesn't actually
handle that case.

AFAICT org-mode commit ec921a2a68 ("Support hourly repeat cookies")
neglected to add support here.

TINYCHANGE
Daniel Gröber 8 months ago
parent
commit
aeb9f036ff
2 changed files with 11 additions and 8 deletions
  1. 8 6
      doc/org-manual.org
  2. 3 2
      lisp/org-macs.el

+ 8 - 6
doc/org-manual.org

@@ -5987,15 +5987,17 @@ various inputs are interpreted, the items filled in by Org mode are in
 | =2012-w04-5=   | \rArr{} Same as above                           |
 
 Furthermore you can specify a relative date by giving, as the /first/
-thing in the input: a plus/minus sign, a number and a letter---=d=,
-=w=, =m= or =y=---to indicate change in days, weeks, months, or
-years.  With a single plus or minus, the date is always relative to
-today.  With a double plus or minus, it is relative to the default
-date.  If instead of a single letter, you use the abbreviation of day
-name, the date is the Nth such day, e.g.:
+thing in the input: a plus/minus sign, a number and a letter---=h=,
+=d=, =w=, =m= or =y=---to indicate a change in hours, days, weeks,
+months, or years.  With =h= the date is relative to the current time,
+with the other letters and a single plus or minus, the date is
+relative to today at 00:00.  With a double plus or minus, it is
+relative to the default date.  If instead of a single letter, you use
+the abbreviation of day name, the date is the Nth such day, e.g.:
 
 | =+0=    | \rArr{} today                       |
 | =.=     | \rArr{} today                       |
+| =+2h=   | \rArr{} two hours from now          |
 | =+4d=   | \rArr{} four days from today        |
 | =+4=    | \rArr{} same as +4d                 |
 | =+2w=   | \rArr{} two weeks from today        |

+ 3 - 2
lisp/org-macs.el

@@ -1228,10 +1228,11 @@ Return 0. if S is not recognized as a valid value."
        ((string= s "<tomorrow>") (+ 86400.0 today))
        ((string= s "<yesterday>") (- today 86400.0))
        ((string-match "\\`<\\([-+][0-9]+\\)\\([hdwmy]\\)>\\'" s)
-	(+ today
+	(+ (if (string= (match-string 2 s) "h") (float-time) today)
 	   (* (string-to-number (match-string 1 s))
 	      (cdr (assoc (match-string 2 s)
-			  '(("d" . 86400.0)   ("w" . 604800.0)
+			  '(("h" . 3600.0)
+			    ("d" . 86400.0)   ("w" . 604800.0)
 			    ("m" . 2678400.0) ("y" . 31557600.0)))))))
        ((string-match org-ts-regexp0 s) (org-2ft s))
        (t 0.)))))