Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Query/Dumper/Concerns/DumpsQueryValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Statamic\Query\Dumper\Concerns;

use DateTimeInterface;
use Illuminate\Support\Carbon;

trait DumpsQueryValues
{
protected function dumpQueryArrayValues($array): string
Expand All @@ -17,6 +20,10 @@ protected function dumpQueryArrayValues($array): string

protected function dumpQueryValue($value): string
{
if ($value instanceof DateTimeInterface) {
$value = Carbon::instance($value)->setTimezone(config('app.timezone'));
}

$this->bindings[] = $value;

return '?';
Expand Down
16 changes: 16 additions & 0 deletions tests/Query/FakesQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Query;

use Illuminate\Support\Carbon;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\User;
use Tests\TestCase;
Expand All @@ -22,6 +23,21 @@ public function it_supports_to_raw_sql()
$this->assertSame("select * from users where name = 'Jack'", $query->toRawSql());
}

#[Test]
public function it_converts_date_bindings_to_the_app_timezone_in_raw_sql()
{
Carbon::setTestNow('2026-07-04 10:00:00');

$query = User::query()->where('created_at', Carbon::today('Europe/Zurich'));

$this->assertSame(
"select * from users where created_at = '2026-07-03 22:00:00'",
$query->toRawSql()
);

Carbon::setTestNow();
}

#[Test]
public function it_supports_dump_raw_sql()
{
Expand Down
Loading