Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DoctrineBridge] Add newDatePointDateType 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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
wkania wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromwkania:datepointtype_and_datetimepointtype

Conversation

wkania
Copy link
Contributor

@wkaniawkania commentedApr 17, 2025
edited
Loading

QA
Branch7.4
Bug fixno
New featureyes
Deprecationsno
LicenseMIT

Doctrine provides bothdate_immutable anddatetime_immutable types. Restricting the conversion of DatePoint only to datetime_immutable is problematic.

New version:

Previouspull request.

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

Old version:

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

Previouspull 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\DatePointTypedatetime_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

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

wkania reacted with thumbs up emoji

@garak
Copy link
Contributor

How is it "problematic"?

@wkania
Copy link
ContributorAuthor

@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.

garak reacted with thumbs up emoji

@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 nameDatePointType is totally accurate for that class. I have no clue what a "date time point" is.

My proposal: Keep theDatePointType as it is and introduce a newDatePointDateType that mapsDatePoint objects toDATE columns.

mtarld reacted with thumbs up emoji

$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 reacted with hooray emojichalasr and mtarld reacted with eyes emoji
@wkania
Copy link
ContributorAuthor

@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
ContributorAuthor

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

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

@wkaniawkaniaforce-pushed thedatepointtype_and_datetimepointtype branch fromacb035e to7d6da09CompareApril 18, 2025 17:27
@wkaniawkania changed the title[DoctrineBridge] rename DatePointType to DateTimePointType, add new DatePointType[DoctrineBridge] add new DatePointDateType Doctrine typeApr 18, 2025
@wkaniawkaniaforce-pushed thedatepointtype_and_datetimepointtype branch from7d6da09 to31ca901CompareMay 2, 2025 18:22
@wkaniawkania requested a review frommtarldMay 2, 2025 18:24
@OskarStarkOskarStark changed the title[DoctrineBridge] add new DatePointDateType Doctrine type[DoctrineBridge] Add newDatePointDateType Doctrine typeMay 5, 2025
@wkaniawkaniaforce-pushed thedatepointtype_and_datetimepointtype branch 2 times, most recently frome5ec79a to9f41419CompareMay 18, 2025 15:13
@wkania
Copy link
ContributorAuthor

Added missingtest

@wkaniawkania requested a review fromOskarStarkMay 18, 2025 15:15
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
@wkaniawkaniaforce-pushed thedatepointtype_and_datetimepointtype branch from9f41419 toc18da98CompareMay 29, 2025 19:55
@wkania
Copy link
ContributorAuthor

Updated Changelog 7.3 ->7.4.

@wkaniawkania requested a review fromGromNaNMay 29, 2025 20:06
@wkania
Copy link
ContributorAuthor

@carsonbot label Feature

@OskarStark
Copy link
Contributor

Just an idea: What about keeping the name add make it configurable instead of having two types?

nicolas-grekas added a commit that referenced this pull requestMay 30, 2025
…Type` and `TimeType` (wkania)This PR was merged into the 7.4 branch.Discussion----------[Form] Add `input=date_point` to `DateTimeType`, `DateType` and `TimeType`| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        || License       | MITBased on [datetime_immutable](https://symfony.com/blog/new-in-symfony-4-1-added-support-for-immutable-dates-in-forms).After [DatePointType](#59900) and [DatePointDateType](#60237), it would be great to use Forms without needing to transform values into the DatePoint type manually.```use Symfony\Component\Form\Extension\Core\Type\DateType;use Symfony\Component\Form\Extension\Core\Type\DateTimeType;use Symfony\Component\Form\Extension\Core\Type\TimeType;use Symfony\Component\Form\Extension\Core\Type\BirthdayType;$builder->add('from', DateType::class, [    'input' => 'date_point',]);$builder->add('from', DateTimeType::class, [    'input' => 'date_point',]);$builder->add('from', TimeType::class, [    'input' => 'date_point',]);$builder->add('from', BirthdayType::class, [    'input' => 'date_point',]);```Alternative: Make symfony/clock a hard requirement and refactor the existing DateTimeImmutableToDateTimeTransformer to return a DatePoint instead. This should not introduce any breaking changes.Commits-------f1160d6 [Form] Add input=date_point to DateTimeType, DateType and TimeType
symfony-splitter pushed a commit to symfony/form that referenced this pull requestMay 30, 2025
…Type` and `TimeType` (wkania)This PR was merged into the 7.4 branch.Discussion----------[Form] Add `input=date_point` to `DateTimeType`, `DateType` and `TimeType`| Q             | A| ------------- | ---| Branch?       | 7.4| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Issues        || License       | MITBased on [datetime_immutable](https://symfony.com/blog/new-in-symfony-4-1-added-support-for-immutable-dates-in-forms).After [DatePointType](symfony/symfony#59900) and [DatePointDateType](symfony/symfony#60237), it would be great to use Forms without needing to transform values into the DatePoint type manually.```use Symfony\Component\Form\Extension\Core\Type\DateType;use Symfony\Component\Form\Extension\Core\Type\DateTimeType;use Symfony\Component\Form\Extension\Core\Type\TimeType;use Symfony\Component\Form\Extension\Core\Type\BirthdayType;$builder->add('from', DateType::class, [    'input' => 'date_point',]);$builder->add('from', DateTimeType::class, [    'input' => 'date_point',]);$builder->add('from', TimeType::class, [    'input' => 'date_point',]);$builder->add('from', BirthdayType::class, [    'input' => 'date_point',]);```Alternative: Make symfony/clock a hard requirement and refactor the existing DateTimeImmutableToDateTimeTransformer to return a DatePoint instead. This should not introduce any breaking changes.Commits-------f1160d6617f [Form] Add input=date_point to DateTimeType, DateType and TimeType
@wkania
Copy link
ContributorAuthor

@OskarStark
I see several drawbacks to this solution:

  • Doctrine provides two separate classes for this:DateImmutableType andDateTimeImmutableType
    (see:Doctrine DBAL Types).

  • We would need to extend theType class and implement two interfaces:
    PhpDateTimeMappingType andPhpDateTimeTimeMappingType.

  • If we introduce some kind of parameter to handle formatting, we won’t be able to use it in
    DatePointType , which is where the decision about the database storage format
    should be made. TheconvertToDatabaseValue method does not allow for that, and it's precisely this method that causes problems in your idea. Each platform (db) has specific format for:getDateFormatString,getDateTimeFormatString andgetTimeFormatString.

  • We should also keep in mind the existence ofTimeImmutableType, which ideally should have a corresponding type namedDatePointTimeType.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mtarldmtarldAwaiting requested review from mtarld

@OskarStarkOskarStarkAwaiting requested review from OskarStark

@GromNaNGromNaNAwaiting requested review from GromNaN

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

8 participants
@wkania@GromNaN@garak@derrabus@OskarStark@mtarld@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp