diff --git a/Classes/Ttree/ContentRepositoryImporter/DataType/Date.php b/Classes/Ttree/ContentRepositoryImporter/DataType/Date.php new file mode 100644 index 0000000..566fef3 --- /dev/null +++ b/Classes/Ttree/ContentRepositoryImporter/DataType/Date.php @@ -0,0 +1,60 @@ +value = clone $value; + } elseif (is_numeric($value)) { + // $value is UNIX timestamp + if ($timestamp = (int)$value) { + $this->value = new \DateTime(); + $this->value->setTimestamp($timestamp); + } else { + $this->value = null; + } + } elseif (is_string($value)) { + // fallback, try to parse $value as a date string + $this->value = new \DateTime($value); + } else { + throw new \Exception(sprintf('Cannot convert %s to a DateTime object', $value)); + } + } + + /** + * Initialize a date value from input + * + * Input value can be a date/time string, parsable by the PHP DateTime class, + * or a numeric value (int or string), which then will be interpreted as a UNIX + * timestamp in the local configured TZ. + * + */ + public static function create($value) + { + return parent::create($value); + } + + /** + * Gets the DateTime value or null, if the datetime was initialized from null or + * an empty timestamp. + * + * @return \DateTime | null + */ + public function getValue() + { + return parent::getValue(); + } +}