Skip to content

Commit

Permalink
Merge pull request #1837 from ste93cry/issue-1820
Browse files Browse the repository at this point in the history
Add support for Doctrine immutable date types
  • Loading branch information
l3pp4rd authored Oct 12, 2017
2 parents 5351c26 + 305e330 commit 79cd1d4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Gedmo/Timestampable/Mapping/Driver/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ class Annotation extends AbstractAnnotationDriver
*/
protected $validTypes = array(
'date',
'date_immutable',
'time',
'time_immutable',
'datetime',
'datetime_immutable',
'datetimetz',
'datetimetz_immutable',
'timestamp',
'zenddate',
'vardatetime',
Expand Down
4 changes: 4 additions & 0 deletions lib/Gedmo/Timestampable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ class Xml extends BaseXml
*/
private $validTypes = array(
'date',
'date_immutable',
'time',
'time_immutable',
'datetime',
'datetime_immutable',
'datetimetz',
'datetimetz_immutable',
'timestamp',
'zenddate',
'vardatetime',
Expand Down
4 changes: 4 additions & 0 deletions lib/Gedmo/Timestampable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ class Yaml extends File implements Driver
*/
private $validTypes = array(
'date',
'date_immutable',
'time',
'time_immutable',
'datetime',
'datetime_immutable',
'datetimetz',
'datetimetz_immutable',
'timestamp',
'zenddate',
'vardatetime',
Expand Down
3 changes: 3 additions & 0 deletions lib/Gedmo/Timestampable/Mapping/Event/Adapter/ODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function getDateValue($meta, $field)
if (isset($mapping['type']) && $mapping['type'] == 'zenddate') {
return new \Zend_Date();
}
if (isset($mapping['type']) && in_array($mapping['type'], array('date_immutable', 'time_immutable', 'datetime_immutable', 'datetimetz_immutable'), true)) {
return new \DateTimeImmutable();
}

return \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))
->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
Expand Down
3 changes: 3 additions & 0 deletions lib/Gedmo/Timestampable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function getDateValue($meta, $field)
if (isset($mapping['type']) && $mapping['type'] == 'zenddate') {
return new \Zend_Date();
}
if (isset($mapping['type']) && in_array($mapping['type'], array('date_immutable', 'time_immutable', 'datetime_immutable', 'datetimetz_immutable'), true)) {
return new \DateTimeImmutable();
}

return \DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''))
->setTimeZone(new \DateTimeZone(date_default_timezone_get()));
Expand Down

0 comments on commit 79cd1d4

Please sign in to comment.