Added support for date:today and date:yesterday

This commit is contained in:
Marcin Kurczewski 2014-08-15 10:07:22 +02:00
parent e93c447758
commit b1ba30adcb
2 changed files with 14 additions and 2 deletions

View file

@ -31,6 +31,8 @@ Command | Description
[search]scoremax:4[/search] | having maximum score of 4 | `score_max` |
[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]date:today[/search] | posted today | - |
[search]date:yesterday[/search] | posted yesterday | - |
[search]date:2000[/search] | posted in year 2000 | - |
[search]date:2000-01[/search] | posted in January, 2000 | - |
[search]date:2000-01-01[/search] | posted on January 1st, 2000 | - |

View file

@ -292,8 +292,18 @@ class PostSearchParser extends AbstractSearchParser
protected static function parseDate($value)
{
$value = trim($value);
if (preg_match('/^(\d{4})$/', $value, $matches))
$value = strtolower(trim($value));
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]);
$timeMin = mktime(0, 0, 0, 1, 1, $year);