From 8f25f0f002d0cbe96aaa46b7702986e44a889f73 Mon Sep 17 00:00:00 2001 From: Alexander Avakov Date: Tue, 27 Feb 2018 13:30:18 +0300 Subject: [PATCH] Fix whereTime method for PostgresGrammar with correct casting. Link: https://www.postgresql.org/docs/9.6/static/functions-datetime.html --- .../Database/Query/Grammars/PostgresGrammar.php | 14 ++++++++++++++ tests/Database/DatabaseQueryBuilderTest.php | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php index bf1315a80d4a..37e91dd4e26e 100755 --- a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php @@ -34,6 +34,20 @@ protected function whereDate(Builder $query, $where) return $this->wrap($where['column']).'::date '.$where['operator'].' '.$value; } + /** + * Compile a "where time" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereTime(Builder $query, $where) + { + $value = $this->parameter($where['value']); + + return $this->wrap($where['column']).'::time '.$where['operator'].' '.$value; + } + /** * Compile a date based where clause. * diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 94d7160aa1df..7dfd77049a6e 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -364,6 +364,14 @@ public function testWhereYearPostgres() $this->assertEquals([0 => 2014], $builder->getBindings()); } + public function testWhereTimePostgres() + { + $builder = $this->getPostgresBuilder(); + $builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00'); + $this->assertEquals('select * from "users" where "created_at"::time >= ?', $builder->toSql()); + $this->assertEquals([0 => '22:00'], $builder->getBindings()); + } + public function testWhereDaySqlite() { $builder = $this->getSQLiteBuilder();