Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 6ca41ab

Browse files
author
Nik Barham
committed
Fix __set to allow standard DateTime objects for datetimes
1 parent 5b84510 commit 6ca41ab

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Automatorm/Orm/Data.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ public function __set($var, $value)
499499
) {
500500
// Special checks for datetimes
501501
if ($value instanceof Time) { // Orm\Time is aware of timezones - preferred
502-
$this->data[$var] = $value->mysql();
503-
} elseif (($datetime = strtotime($value)) !== false) {// Fall back to standard strings
502+
$this->data[$var] = $value->mysql();
503+
} elseif ($value instanceof \DateTime) { // Fall back to standard DateTime object
504+
$this->data[$var] = $value->format(Time::MYSQL_DATE);
505+
} elseif (($datetime = strtotime($value)) !== false) { // Fall back to standard strings
504506
$this->data[$var] = date(Time::MYSQL_DATE, $datetime);
505507
} elseif (is_null($value)) { // Allow "null"
506508
$this->data[$var] = null;

0 commit comments

Comments
 (0)