Added support for date:today and date:yesterday
This commit is contained in:
parent
e93c447758
commit
b1ba30adcb
2 changed files with 14 additions and 2 deletions
|
@ -31,6 +31,8 @@ Command | Description
|
||||||
[search]scoremax:4[/search] | having maximum score of 4 | `score_max` |
|
[search]scoremax:4[/search] | having maximum score of 4 | `score_max` |
|
||||||
[search]tagmin:7[/search] | tagged with at least seven tags | `tag_min` |
|
[search]tagmin:7[/search] | tagged with at least seven tags | `tag_min` |
|
||||||
[search]tagmax:7[/search] | tagged with at most seven tags | `tax_max` |
|
[search]tagmax:7[/search] | tagged with at most seven tags | `tax_max` |
|
||||||
|
[search]date:today[/search] | posted today | - |
|
||||||
|
[search]date:yesterday[/search] | posted yesterday | - |
|
||||||
[search]date:2000[/search] | posted in year 2000 | - |
|
[search]date:2000[/search] | posted in year 2000 | - |
|
||||||
[search]date:2000-01[/search] | posted in January, 2000 | - |
|
[search]date:2000-01[/search] | posted in January, 2000 | - |
|
||||||
[search]date:2000-01-01[/search] | posted on January 1st, 2000 | - |
|
[search]date:2000-01-01[/search] | posted on January 1st, 2000 | - |
|
||||||
|
|
|
@ -292,8 +292,18 @@ class PostSearchParser extends AbstractSearchParser
|
||||||
|
|
||||||
protected static function parseDate($value)
|
protected static function parseDate($value)
|
||||||
{
|
{
|
||||||
$value = trim($value);
|
$value = strtolower(trim($value));
|
||||||
if (preg_match('/^(\d{4})$/', $value, $matches))
|
if ($value == 'today')
|
||||||
|
{
|
||||||
|
$timeMin = mktime(0, 0, 0);
|
||||||
|
$timeMax = mktime(24, 0, -1);
|
||||||
|
}
|
||||||
|
elseif ($value == 'yesterday')
|
||||||
|
{
|
||||||
|
$timeMin = mktime(-24, 0, 0);
|
||||||
|
$timeMax = mktime(0, 0, -1);
|
||||||
|
}
|
||||||
|
elseif (preg_match('/^(\d{4})$/', $value, $matches))
|
||||||
{
|
{
|
||||||
$year = intval($matches[1]);
|
$year = intval($matches[1]);
|
||||||
$timeMin = mktime(0, 0, 0, 1, 1, $year);
|
$timeMin = mktime(0, 0, 0, 1, 1, $year);
|
||||||
|
|
Loading…
Reference in a new issue