-
Notifications
You must be signed in to change notification settings - Fork 16
fix: Carbon was being altered by google/cloud-spanner #264
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
Conversation
WalkthroughThis pull request modifies the date-time binding behavior in the connection handling. It updates the logic in the Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 PHPStan (2.0.3)/bin/bash: line 1: /vendor/bin/phpstan: No such file or directory Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/ConnectionTest.php (1)
635-641
: LGTM! Well-designed test case.The test effectively verifies that the timezone of a mutable Carbon instance is preserved during SQL binding. This directly validates the fix implemented in
Connection.php
.Consider adding these additional test cases to strengthen the coverage:
public function test_binding_mutable_carbon_doesnt_change_timezone(): void { $conn = $this->getDefaultConnection(); $now = now()->setTimezone('Asia/Tokyo'); $conn->select('SELECT ?', [$now]); $this->assertSame('Asia/Tokyo', $now->getTimezone()->getName()); + + // Test with DateTimeImmutable + $immutable = DateTimeImmutable::createFromMutable($now); + $conn->select('SELECT ?', [$immutable]); + $this->assertSame('Asia/Tokyo', $immutable->getTimezone()->getName()); + + // Test with array of date-time objects + $dates = [$now, $immutable]; + $conn->select('SELECT ?', [$dates]); + $this->assertSame('Asia/Tokyo', $dates[0]->getTimezone()->getName()); + $this->assertSame('Asia/Tokyo', $dates[1]->getTimezone()->getName()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Connection.php
(2 hunks)tests/ConnectionTest.php
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run-PHPUnit
🔇 Additional comments (2)
src/Connection.php (2)
28-28
: LGTM!Added import for
DateTimeImmutable
which is used in the updatedprepareBinding
method.
465-469
:✅ Verification successful
Excellent fix for preserving the original DateTime object!
The changes effectively prevent the modification of the original DateTime object by:
- Using the original DateTimeImmutable instance directly
- Creating a new DateTimeImmutable for mutable instances
This fixes the issue where Carbon's timezone was being altered by the Timestamp constructor.
Let's verify that this change doesn't introduce any regressions in date-time handling:
🏁 Script executed:
#!/bin/bash # Description: Search for other date-time related code that might be affected by this change # Test: Search for Timestamp usage rg -A 5 'new Timestamp' # Test: Search for Carbon usage rg -A 5 'Carbon::'Length of output: 5890
Date-Time Handling Update Verified & Approved
Our investigation confirms that the new implementation in
src/Connection.php
correctly preserves the original DateTime object by:
- Cloning mutable DateTime instances via creating a new DateTimeImmutable.
- Maintaining consistent usage of
new Timestamp($value)
across the codebase (see tests intests/Query/DatetimeTest.php
and related classes).- Preserving expected behavior in related Carbon invocations without introducing any regressions.
Great work on this fix!
Caused by this.
Summary by CodeRabbit
Bug Fixes
Tests