8000 [DoctrineBridge] Add new `DatePointDateType` Doctrine type by wkania · Pull Request #60237 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Add new DatePointDateType Doctrine type #60237

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: 7.3
Choose a base branch
from

Conversation

wkania
Copy link
Contributor
@wkania wkania commented Apr 17, 2025
Q A
Branch 7.3
Bug fix no
New feature yes
Deprecations no
License MIT

Doctri 8000 ne provides both date_immutable and datetime_immutable types. Restricting the conversion of DatePoint only to datetime_immutable is problematic.

Therefore, I propose renaming the current DatePointType to DateTimePointType, and introducing a new DatePointType.

Previous pull request.

If this pull request is to be merged, it should be included in version 7.3 to avoid any breaking changes in the future.

doctrine:
    dbal:
        types:
            date_point: Symfony\Bridge\Doctrine\Types\DatePointType
            datetime_point: Symfony\Bridge\Doctrine\Types\DateTimePointType
#[ORM\Column(type: 'date_point')]
public DatePoint $birthday;

#[ORM\Column(type: 'datetime_point')]
public DatePoint $createdAt;            

@GromNaN
Copy link
Member
GromNaN commented Apr 17, 2025

I removed the direct mentions to avoid notification spam when the PR is merged

@garak
Copy link
Contributor
garak commented Apr 17, 2025

How is it "problematic"?

@wkania
Copy link
Contributor Author
wkania commented Apr 17, 2025

@garak For example, Doctrine Migrations for PostgreSQL will generate migrations using the TIMESTAMP type instead of DATE. The schema will never be fully synchronized if you try to force it. Relational databases have dedicated data types for storing DATE and DATETIME, which is why PHP's DateTime is represented by two separate types in Doctrine.

@derrabus
Copy link
Member

First of all, thank you for bringing up this topic. Secondly: Naming things is hard.

DatePoint is the class that the type maps to, so the name DatePointType is totally accurate for that class. I have no clue what a "date time point" is.

My proposal: Keep the DatePointType as it is and introduce a new DatePointDateType that maps DatePoint objects to DATE columns.

$format = 'Y-m-d H:i:s.u';
$date = '2025-03-03';
$actual = $this->type->convertToPHPValue($date, self::getSqlitePlatform());
$expected = DatePoint::createFromFormat('!Y-m-d', $date);
Copy link
Member

Choose a reason for hiding this comment

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

TIL about the !:

Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to zero-like values ( 0 for hour, minute, second and fraction, 1 for month and day, 1970 for year and UTC for timezone information)
Without !, all fields will be set to the current date and time.

@wkania
Copy link
Contributor Author
wkania commented Apr 17, 2025

@derrabus Ok, so we're leaning more towards Symfony's naming conventions rather than Doctrine's. You contribute a lot to Doctrine, so this is an important note.
Also, I will add a separate entry in the Changelog.

@wkania
Copy link
Contributor Author
wkania commented Apr 18, 2025

@derrabus After the changes you suggested, this is how it will look.

doctrine:
    dbal:
        types:
            date_point: Symfony\Bridge\Doctrine\Types\DatePointType
            date_point_date: Symfony\Bridge\Doctrine\Types\DatePointDateType
#[ORM\Column(type: 'date_point_date')]
public DatePoint $birthday;

#[ORM\Column(type: 'date_point')]
public DatePoint $createdAt; 

@wkania wkania force-pushed the datepointtype_and_datetimepointtype branch from acb035e to 7d6da09 Compare April 18, 2025 17:27
@wkania wkania changed the title [DoctrineBridge] rename DatePointType to DateTimePointType, add new DatePointType [DoctrineBridge] add new DatePointDateType Doctrine type Apr 18, 2025
@wkania wkania force-pushed the datepointtype_and_datetimepointtype branch from 7d6da09 to 31ca901 Compare May 2, 2025 18:22
@wkania wkania requested a review from mtarld May 2, 2025 18:24
@OskarStark OskarStark changed the title [DoctrineBridge] add new DatePointDateType Doctrine type [DoctrineBridge] Add new DatePointDateType Doctrine type May 5, 2025
@wkania wkania force-pushed the datepointtype_and_datetimepointtype branch from 31ca901 to e5ec79a Compare May 18, 2025 15:08
@wkania wkania force-pushed the datepointtype_and_datetimepointtype branch from e5ec79a to 9f41419 Compare May 18, 2025 15:13
@wkania
Copy link
Contributor Author
wkania commented May 18, 2025

Added missing test

@wkania wkania requested a review from OskarStark May 18, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0