From b1ba30adcb6d560743dd673cf0bb3fb71406602a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 15 Aug 2014 10:07:22 +0200 Subject: [PATCH] Added support for date:today and date:yesterday --- data/help.md | 2 ++ src/Models/SearchParsers/PostSearchParser.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/data/help.md b/data/help.md index 03aa584c..0f95292c 100644 --- a/data/help.md +++ b/data/help.md @@ -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 | - | diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index 83284672..309e5b6a 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -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);