diff --git a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php index 67359b569693..bc60a4bea846 100755 --- a/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php @@ -116,6 +116,18 @@ protected function whereYear(Builder $query, $where) return $this->dateBasedWhere('%Y', $query, $where); } + /** + * Compile a "where time" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereTime(Builder $query, $where) + { + return $this->dateBasedWhere('%H:%M:%S', $query, $where); + } + /** * Compile a date based where clause. * diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 6b6fe8cf1f82..ac5b228302e2 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -412,6 +412,22 @@ public function testWhereYearSqlite() $this->assertEquals([0 => 2014], $builder->getBindings()); } + public function testWhereTimeSqlite() + { + $builder = $this->getSQLiteBuilder(); + $builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00'); + $this->assertEquals('select * from "users" where strftime(\'%H:%M:%S\', "created_at") >= ?', $builder->toSql()); + $this->assertEquals([0 => '22:00'], $builder->getBindings()); + } + + public function testWhereTimeOperatorOptionalSqlite() + { + $builder = $this->getSQLiteBuilder(); + $builder->select('*')->from('users')->whereTime('created_at', '22:00'); + $this->assertEquals('select * from "users" where strftime(\'%H:%M:%S\', "created_at") = ?', $builder->toSql()); + $this->assertEquals([0 => '22:00'], $builder->getBindings()); + } + public function testWhereDaySqlServer() { $builder = $this->getSqlServerBuilder();