-
Couldn't load subscription status.
- Fork 1.4k
PHPORM-234 Convert dates in DB Query results #3119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,11 @@ | |
|
|
||
| namespace MongoDB\Laravel\Tests; | ||
|
|
||
| use Carbon\Carbon; | ||
| use Illuminate\Auth\Passwords\PasswordBroker; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Hash; | ||
| use MongoDB\BSON\UTCDateTime; | ||
| use MongoDB\Laravel\Tests\Models\User; | ||
|
|
||
| use function bcrypt; | ||
|
|
@@ -63,7 +63,7 @@ function ($actualUser, $actualToken) use ($user, &$token) { | |
| $reminder = DB::table('password_reset_tokens')->first(); | ||
| $this->assertEquals('[email protected]', $reminder->email); | ||
| $this->assertNotNull($reminder->token); | ||
| $this->assertInstanceOf(UTCDateTime::class, $reminder->created_at); | ||
| $this->assertInstanceOf(Carbon::class, $reminder->created_at); | ||
|
|
||
| $credentials = [ | ||
| 'email' => '[email protected]', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| namespace MongoDB\Laravel\Tests; | ||
|
|
||
| use Carbon\Carbon; | ||
| use DateTime; | ||
| use DateTimeImmutable; | ||
| use Illuminate\Support\Facades\Date; | ||
|
|
@@ -33,7 +34,6 @@ | |
| use function md5; | ||
| use function sort; | ||
| use function strlen; | ||
| use function strtotime; | ||
|
|
||
| class QueryBuilderTest extends TestCase | ||
| { | ||
|
|
@@ -676,27 +676,32 @@ public function testUpdateSubdocument() | |
| public function testDates() | ||
| { | ||
| DB::table('users')->insert([ | ||
| ['name' => 'John Doe', 'birthday' => new UTCDateTime(Date::parse('1980-01-01 00:00:00'))], | ||
| ['name' => 'Robert Roe', 'birthday' => new UTCDateTime(Date::parse('1982-01-01 00:00:00'))], | ||
| ['name' => 'Mark Moe', 'birthday' => new UTCDateTime(Date::parse('1983-01-01 00:00:00.1'))], | ||
| ['name' => 'Frank White', 'birthday' => new UTCDateTime(Date::parse('1960-01-01 12:12:12.1'))], | ||
| ['name' => 'John Doe', 'birthday' => Date::parse('1980-01-01 00:00:00')], | ||
| ['name' => 'Robert Roe', 'birthday' => Date::parse('1982-01-01 00:00:00')], | ||
| ['name' => 'Mark Moe', 'birthday' => Date::parse('1983-01-01 00:00:00.1')], | ||
| ['name' => 'Frank White', 'birthday' => Date::parse('1975-01-01 12:12:12.1')], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the date to avoid the issue reported in PHPC-2429 |
||
| ]); | ||
|
|
||
| $user = DB::table('users') | ||
| ->where('birthday', new UTCDateTime(Date::parse('1980-01-01 00:00:00'))) | ||
| ->where('birthday', Date::parse('1980-01-01 00:00:00')) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted that |
||
| ->first(); | ||
| $this->assertEquals('John Doe', $user->name); | ||
|
|
||
| $user = DB::table('users') | ||
| ->where('birthday', new UTCDateTime(Date::parse('1960-01-01 12:12:12.1'))) | ||
| ->where('birthday', Date::parse('1975-01-01 12:12:12.1')) | ||
| ->first(); | ||
|
|
||
| $this->assertEquals('Frank White', $user->name); | ||
| $this->assertInstanceOf(Carbon::class, $user->birthday); | ||
| $this->assertSame('1975-01-01 12:12:12.100000', $user->birthday->format('Y-m-d H:i:s.u')); | ||
|
|
||
| $user = DB::table('users')->where('birthday', '=', new DateTime('1980-01-01 00:00:00'))->first(); | ||
| $this->assertEquals('John Doe', $user->name); | ||
| $this->assertInstanceOf(Carbon::class, $user->birthday); | ||
| $this->assertSame('1980-01-01 00:00:00.000000', $user->birthday->format('Y-m-d H:i:s.u')); | ||
|
|
||
| $start = new UTCDateTime(1000 * strtotime('1950-01-01 00:00:00')); | ||
| $stop = new UTCDateTime(1000 * strtotime('1981-01-01 00:00:00')); | ||
| $start = new UTCDateTime(new DateTime('1950-01-01 00:00:00')); | ||
| $stop = new UTCDateTime(new DateTime('1981-01-01 00:00:00')); | ||
|
|
||
| $users = DB::table('users')->whereBetween('birthday', [$start, $stop])->get(); | ||
| $this->assertCount(2, $users); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll note that ODM also applies the default timezone in its DateType class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, thanks for the investigation.