Browse Source

Avoiding fatal errors when trying to marshal a DatTimeObject

It should be perfectly valid to try to marshal a DateTime object, this
will now return the same object as there is nothing to be marshaled
Jose Lorenzo Rodriguez 11 years ago
parent
commit
f449e237fc

+ 4 - 0
src/Database/Type/DateTimeType.php

@@ -85,6 +85,10 @@ class DateTimeType extends \Cake\Database\Type {
  * @return \Carbon\Carbon
  */
 	public function marshal($value) {
+		if ($value instanceof \DateTime) {
+			return $value;
+		}
+
 		$class = static::$dateTimeClass;
 		try {
 			if ($value === '' || $value === null || $value === false || $value === true) {

+ 4 - 0
tests/TestCase/Database/Type/DateTimeTypeTest.php

@@ -147,6 +147,10 @@ class DateTimeTypeTest extends TestCase {
 				],
 				new Time('2014-02-14 00:00:00')
 			],
+			[
+				Time::now(),
+				Time::now()
+			]
 		];
 	}