Skip to content

Commit 4425180

Browse files
committed
Use the current timezone when reading an UTCDateTime
1 parent 053a893 commit 4425180

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: src/Query/Builder.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Carbon\CarbonPeriod;
1010
use Closure;
1111
use DateTimeInterface;
12+
use DateTimeZone;
1213
use Illuminate\Database\Query\Builder as BaseBuilder;
1314
use Illuminate\Database\Query\Expression;
1415
use Illuminate\Support\Arr;
@@ -40,6 +41,7 @@
4041
use function call_user_func_array;
4142
use function count;
4243
use function ctype_xdigit;
44+
use function date_default_timezone_get;
4345
use function dd;
4446
use function dump;
4547
use function end;
@@ -1662,7 +1664,8 @@ private function aliasIdForResult(array|object $values): array|object
16621664

16631665
foreach ($values as $key => $value) {
16641666
if ($value instanceof UTCDateTime) {
1665-
$values[$key] = Date::instance($value->toDateTime());
1667+
$values[$key] = Date::instance($value->toDateTime())
1668+
->setTimezone(new DateTimeZone(date_default_timezone_get()));
16661669
} elseif (is_array($value) || $value instanceof stdClass) {
16671670
$values[$key] = $this->aliasIdForResult($value);
16681671
}
@@ -1677,7 +1680,8 @@ private function aliasIdForResult(array|object $values): array|object
16771680

16781681
foreach (get_object_vars($values) as $key => $value) {
16791682
if ($value instanceof UTCDateTime) {
1680-
$values->{$key} = Date::instance($value->toDateTime());
1683+
$values->{$key} = Date::instance($value->toDateTime())
1684+
->setTimezone(new DateTimeZone(date_default_timezone_get()));
16811685
} elseif (is_array($value) || $value instanceof stdClass) {
16821686
$values->{$key} = $this->aliasIdForResult($value);
16831687
}

Diff for: tests/AuthTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace MongoDB\Laravel\Tests;
66

7+
use Carbon\Carbon;
78
use Illuminate\Auth\Passwords\PasswordBroker;
89
use Illuminate\Support\Facades\Auth;
910
use Illuminate\Support\Facades\DB;
@@ -63,7 +64,7 @@ function ($actualUser, $actualToken) use ($user, &$token) {
6364
$reminder = DB::table('password_reset_tokens')->first();
6465
$this->assertEquals('[email protected]', $reminder->email);
6566
$this->assertNotNull($reminder->token);
66-
$this->assertInstanceOf(UTCDateTime::class, $reminder->created_at);
67+
$this->assertInstanceOf(Carbon::class, $reminder->created_at);
6768

6869
$credentials = [
6970
'email' => '[email protected]',

0 commit comments

Comments
 (0)