Skip to content

Update "Custom Mapping Types" documentation for a fully working example #2778

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

Open
wants to merge 1 commit into
base: 2.11.x
Choose a base branch
from

Conversation

fnash
Copy link

@fnash fnash commented Jun 10, 2025

Q A
Type improvement
BC Break no
Fixed issues

Summary

Update "Custom Mapping Types" documentation for a fully working example of DateTimeWithTimezoneType

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Good catch. Could you revert the namespace changes please?

}

public function convertToDatabaseValue($value): array
{
if (! isset($value['utc'], $value['tz'])) {
throw new RuntimeException('Database value cannot be converted to date with timezone. Expected array with "utc" and "tz" keys.');
if (!$value instanceof \DateTimeImmutable) {
Copy link
Member

Choose a reason for hiding this comment

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

Any DateTimeInterface would be accepted here.

Suggested change
if (!$value instanceof \DateTimeImmutable) {
if (!$value instanceof \DateTimeInterface) {

Copy link
Author

Choose a reason for hiding this comment

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

Indeed but it will not work with a \DateTime Document field for example because ::convertToPHPValue() returns a \DateTimeImmutable anyway.
Enforcing only one type in the two conversion is better IMO.

@fnash fnash force-pushed the fna/update-custom-type-documentation branch from d19a89c to eae430b Compare June 10, 2025 17: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.

2 participants