mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-3742: Use UTCDatetimeType with lifecycle callbacks #4591
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (May 22, 2015).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user mcarra66:
I'm trying to save my entities (yaml), which have lifecyclecallbacks with a createdAt and updatedAt UTCDatetimeType fields. If I save them with prePersist or preUpdate, the insert of new rows into the mysql database fails because of blank date fields, but they are already populated in my entity.
If I replace the UTCDateTimeType by datetime, it works.
@doctrinebot commented on GitHub (May 22, 2015):
Comment created by mcarra66:
I'm using
UTCDateTimeTypefrom: http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.htmlIt makes a
$value->format($format, $timezone)I was passing a
\Datetimeobject, so format only has one parameter, not 2...Then, Or I'm passing an unexpected$valueor the format method is not properly coded there.So, I've modified
convertToDatabaseValueto the following:@doctrinebot commented on GitHub (May 22, 2015):
Comment created by @ocramius:
[~mcarra66] what exactly is the action to be taken here? It's unclear to me.
@doctrinebot commented on GitHub (May 22, 2015):
Comment created by mcarra66:
I replaced the metod convertToDatabaseValue from http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.html with mine.
For example:
date_default_timezone_set('Europe/Madrid'); $expireAt = new \DateTime(); $entity = newEntity(); $entity->setExpireAt($expireAt);$this->em->persist($entity);
$this->em->flush();
My expireAt field is UTCDateTimeType, so it will be converted from my Europe/Madrid timezone to UTC. But using the code from URL it doesn't works because ->format() method has 2 parameters instead of one.
@Ocramius commented on GitHub (Aug 23, 2018):
Closing as won't fix: please refer to https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/cookbook/working-with-datetime.html instead