Skip to content

Commit

Permalink
Fix whereTime method for SQLiteGrammar with correct formatting. (#23321)
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguinjkeke authored and taylorotwell committed Feb 27, 2018
1 parent 65b6ad5 commit 9288069
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9288069

Please sign in to comment.