From 1ddb2e2754f2fa108f34038b0b417b4c02bafae9 Mon Sep 17 00:00:00 2001 From: Remus Lazar Date: Tue, 15 Sep 2015 20:15:10 +0200 Subject: [PATCH] Date DataType implemented --- .../DataType/Date.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Classes/Ttree/ContentRepositoryImporter/DataType/Date.php 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(); + } +}