]> granicus.if.org Git - neomutt/commitdiff
Allow relative date hour/min/sec offsets
authorKevin McCarthy <kevin@8t8.us>
Tue, 6 Nov 2018 21:21:20 +0000 (13:21 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 26 Nov 2018 18:27:21 +0000 (18:27 +0000)
These might be useful for index-format-hook pattern matching for some
people.

doc/manual.xml.head
pattern.c

index 9007a954031c40ee984232a7d4049c131b8a5a5e..088fe1a79bdc3cba00ec73f4fb5665952bf6659a 100644 (file)
@@ -8025,8 +8025,49 @@ set index_format="%4C %Z %{%b %d} %-15.15L (%?l?%4l&amp;%4c?)%*  %s"
           </itemizedlist>
           <para>
             <emphasis>offset</emphasis> is specified as a positive number with
-            one of the units from <xref linkend="tab-date-units" />.
+            one of the units from <xref linkend="tab-rel-date-units" />.
           </para>
+          <table id="tab-rel-date-units">
+            <title>Relative date units</title>
+            <tgroup cols="2">
+              <thead>
+                <row>
+                  <entry>Unit</entry>
+                  <entry>Description</entry>
+                </row>
+              </thead>
+              <tbody>
+                <row>
+                  <entry>y</entry>
+                  <entry>Years</entry>
+                </row>
+                <row>
+                  <entry>m</entry>
+                  <entry>Months</entry>
+                </row>
+                <row>
+                  <entry>w</entry>
+                  <entry>Weeks</entry>
+                </row>
+                <row>
+                  <entry>d</entry>
+                  <entry>Days</entry>
+                </row>
+                <row>
+                  <entry>H</entry>
+                  <entry>Hours</entry>
+                </row>
+                <row>
+                  <entry>M</entry>
+                  <entry>Minutes</entry>
+                </row>
+                <row>
+                  <entry>S</entry>
+                  <entry>Seconds</entry>
+                </row>
+              </tbody>
+            </tgroup>
+          </table>
           <para>
             Example: to select messages less than 1 month old, you would use
           </para>
index 197445a640ea75829396056ceb626c78ec661db0..f9ede5917db8074e7d72488a62e53764dbcc3c2d 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -272,6 +272,15 @@ static const char *get_offset(struct tm *tm, const char *s, int sign)
     case 'd':
       tm->tm_mday += offset;
       break;
+    case 'H':
+      tm->tm_hour += offset;
+      break;
+    case 'M':
+      tm->tm_min += offset;
+      break;
+    case 'S':
+      tm->tm_sec += offset;
+      break;
     default:
       return s;
   }
@@ -471,6 +480,7 @@ static bool eat_date(struct Pattern *pat, struct Buffer *s, struct Buffer *err)
 {
   struct Buffer buf;
   struct tm min, max;
+  char *offset_type = NULL;
 
   mutt_buffer_init(&buf);
   char *pexpr = s->dptr;
@@ -529,9 +539,16 @@ static bool eat_date(struct Pattern *pat, struct Buffer *s, struct Buffer *err)
       if (buf.data[0] == '=')
         exact++;
     }
-    tm->tm_hour = 23;
-    tm->tm_min = 59;
-    tm->tm_sec = 59;
+
+    /* Reset the HMS unless we are relative matching using one of those
+     * offsets. */
+    strtol(s->data + 1, &offset_type, 0);
+    if (!(*offset_type && strchr("HMS", *offset_type)))
+    {
+      tm->tm_hour = 23;
+      tm->tm_min = 59;
+      tm->tm_sec = 59;
+    }
 
     /* force negative offset */
     get_offset(tm, buf.data + 1, -1);