Skip to content
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

PHPORM-143 Ensure date are read using local timezone #2739

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Feb 28, 2024

Fix PHPORM-143
Fix #2719

In #2705 (a5cf5cb), the conversion from MongoDB\BSON\UTCDateTime to Carbon\Date was modified in a way that no longer change use the local timezone. UTCDateTime::asDateTime always return a DateTime instance with UTC timezone, while le previous Date::createFromTimestampMs($timestampMs) was using the local timezone.

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@GromNaN GromNaN added this to the 4.1 milestone Feb 28, 2024
@GromNaN GromNaN requested a review from a team as a code owner February 28, 2024 10:22
@GromNaN GromNaN changed the base branch from 4.2 to 4.1 February 28, 2024 10:28
public function testDateUseLocalTimeZone(): void
{
$tz = 'Australia/Sydney';
date_default_timezone_set($tz);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test permanently alters the state of the environment. Would it be preferable to capture the current timezone first and then restore it at the end of the test?

If you're concerned about a failure interrupting things, you can use tearDown(), but I don't think that's necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timezone is reset before each test by this: https://github.com/orchestral/testbench-core/blob/bf3de053bc6566210c0c336635d03e97e270f205/src/Concerns/CreatesApplication.php#L389-L391

But I can explicitly reset the timezone to prevent any regression.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize the tests in this project used OrchestraTestCase instead of PHPUnit directly. I think a comment explaining that would be sufficient.

Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending the timezone things in the tests.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a comment explaining the timezone being changed isn't a problem.

@GromNaN GromNaN merged commit 7af9a1a into mongodb:4.1 Mar 1, 2024
15 checks passed
@GromNaN GromNaN deleted the PHPORM-143 branch March 1, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datetime casts not considering timezone
3 participants