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

[3.x]: craft\helpers\Db::parseDateParam doesn't like DateTimeImmutable #13656

Closed
msbit opened this issue Sep 7, 2023 · 2 comments
Closed

[3.x]: craft\helpers\Db::parseDateParam doesn't like DateTimeImmutable #13656

msbit opened this issue Sep 7, 2023 · 2 comments

Comments

@msbit
Copy link

msbit commented Sep 7, 2023

What happened?

Consider the following:

>>> craft\helpers\Db::parseDateParam("column", new DateTimeImmutable());
=> [
     "column" => [
       "2023-09-07 02:52:10",
       "1970-01-01 00:00:03",
       "",
     ],
   ]

vs:

>>> craft\helpers\Db::parseDateParam("column", new DateTime());
=> [
     "column" => "2023-09-07 02:52:16",
   ]

This appears to be due to the following checks against DateTime specifically:

https://github.com/craftcms/cms/blob/3.9.1/src/helpers/Db.php#L1253
https://github.com/craftcms/cms/blob/3.9.1/src/helpers/DateTimeHelper.php#L87

https://github.com/craftcms/cms/blob/4.5.3/src/helpers/Db.php#L1586
https://github.com/craftcms/cms/blob/4.5.3/src/helpers/DateTimeHelper.php#L91

I haven't checked 4.x, but in 3.x changing these to check directly against DateTimeInterface gives me the correct result in the first example.

Craft CMS version

3.8.9

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

brandonkelly commented Sep 10, 2023

Just added support for DateTimeImmutable for the next Craft 4 release.

We’re generally no longer maintaining Craft 3, save for security fixes and some other bug fixes when it makes sense, at our discretion. In this case, the fix involves DateTime::createFromImmutable() which was added in PHP 7.3. So until you are ready to update to Craft 4, you will have to ensure you’re passing a DateTime instance into the param.

@brandonkelly
Copy link
Member

Craft 4.5.4 is out with that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants