/** * @test */ public function convertFromSupportsDateTimeSubClasses() { $className = 'DateTimeSubClass' . md5(uniqid(mt_rand(), true)); if (version_compare(PHP_VERSION, '7.0.0-dev')) { eval(' class ' . $className . ' extends \\DateTime { public static function createFromFormat($format, $time, $timezone = NULL) { return new ' . $className . '(); } public function foo() { return "Bar"; } } '); } else { eval(' class ' . $className . ' extends \\DateTime { public static function createFromFormat($format, $time, \\DateTimeZone $timezone = NULL) { return new ' . $className . '(); } public function foo() { return "Bar"; } } '); } $date = $this->converter->convertFrom('2005-08-15T15:52:01+00:00', $className); $this->assertInstanceOf($className, $date); $this->assertSame('Bar', $date->foo()); }
public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = null) { if (isset($source['dateFormat']) && $source['dateFormat'] === 'MULTIPLE') { $source['dateFormat'] = 'Y-m-d'; $result = parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration); if ($result instanceof Error) { $source['dateFormat'] = 'd.m.Y'; $result = parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration); } return $result; } else { return parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration); } }
/** * @test */ public function convertFromSupportsDateTimeSubClasses() { $className = 'DateTimeSubClass' . md5(uniqid(mt_rand(), TRUE)); eval(' class ' . $className . ' extends \\DateTime { public static function createFromFormat($format, $time, $timezone = NULL) { return new ' . $className . '(); } public function foo() { return "Bar"; } } '); $date = $this->converter->convertFrom('2005-08-15T15:52:01+00:00', $className); $this->assertInstanceOf($className, $date); $this->assertSame('Bar', $date->foo()); }