Commit 762c0c43 authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Allow relative date hour/min/sec offsets.

These might be useful for index-format-hook pattern matching for some
people.
parent 79741a49
Pipeline #35654193 passed with stages
in 15 minutes and 31 seconds
......@@ -5673,9 +5673,27 @@ as:
<para>
<emphasis>offset</emphasis> is specified as a positive number with one
of the units from <xref linkend="tab-date-units"/>.
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>
......
......@@ -461,6 +461,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;
}
......@@ -579,6 +588,7 @@ static const char * parse_date_range (const char* pc, struct tm *min,
static int eval_date_minmax (pattern_t *pat, const char *s, BUFFER *err)
{
struct tm min, max;
char *offset_type;
memset (&min, 0, sizeof (min));
/* the `0' time is Jan 1, 1970 UTC, so in order to prevent a negative time
......@@ -622,8 +632,15 @@ static int eval_date_minmax (pattern_t *pat, const char *s, BUFFER *err)
if (s[0] == '=')
exact++;
}
tm->tm_hour = 23;
tm->tm_min = tm->tm_sec = 59;
/* Reset the HMS unless we are relative matching using one of those
* offsets. */
strtol (s + 1, &offset_type, 0);
if (!(*offset_type && strchr ("HMS", *offset_type)))
{
tm->tm_hour = 23;
tm->tm_min = tm->tm_sec = 59;
}
/* force negative offset */
get_offset (tm, s + 1, -1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment