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

Fix doctrine orm carbon type #2045

Merged

Conversation

Flodess
Copy link
Contributor

@Flodess Flodess commented Mar 25, 2020

Hello,

When I tried the new carbon type, I got a "Data missing".

This is due to postgres not using the 'Y-m-d H:i:s.u' format but 'Y-m-d H:i:s' when microseconds are set to zero.

The solution is based on this comment :
doctrine/dbal#2873 (comment)

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Mar 26, 2020

I think here we could simply use parse instead. Does the following work fine for you with Postgres?

$date = $class::parse($value);

Instead of the whole ternary expression.

This should also ease to change the precision keeping existing data.

For the record, I highly recommend to store microseconds precision. This is easy to trim data you don't need but impossible to get the data you didn't store.

Copy link
Collaborator

@kylekatarnls kylekatarnls left a comment

Choose a reason for hiding this comment

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

I approve, but let's try first if we can optimize this part of the code.

src/Carbon/Doctrine/CarbonType.php Outdated Show resolved Hide resolved
When microseconds are set to zero, postgres doesn't use 'Y-m-d H:i:s.u' format
but 'Y-m-d H:i:s'.
@Flodess Flodess force-pushed the fix-doctrine-orm-carbon-type branch from 97a58e8 to ce15089 Compare March 26, 2020 13:00
@kylekatarnls kylekatarnls added this to the 2.32.1 milestone Mar 26, 2020
@kylekatarnls kylekatarnls merged commit ecb525c into briannesbitt:master Mar 26, 2020
@kylekatarnls
Copy link
Collaborator

Thanks, I will publish a patch for that today.

@Flodess
Copy link
Contributor Author

Flodess commented Mar 26, 2020

Waouh, that was fast! Thx :)

@kylekatarnls
Copy link
Collaborator

2.32.1 released.

@Flodess Flodess deleted the fix-doctrine-orm-carbon-type branch March 30, 2020 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants