diff --git a/src/Dibi/DateTime.php b/src/Dibi/DateTime.php index 18ac8cba..f0ff359d 100644 --- a/src/Dibi/DateTime.php +++ b/src/Dibi/DateTime.php @@ -40,21 +40,6 @@ class DateTime extends \DateTime } - public function setTimestamp($timestamp): self - { - $zone = $this->getTimezone(); - $this->__construct('@' . $timestamp); - return $this->setTimezone($zone); - } - - - public function getTimestamp() - { - $ts = $this->format('U'); - return is_float($tmp = $ts * 1) ? $ts : $tmp; - } - - public function __toString(): string { return $this->format('Y-m-d H:i:s.u'); diff --git a/tests/dibi/DateTime.phpt b/tests/dibi/DateTime.phpt new file mode 100644 index 00000000..5621c9b0 --- /dev/null +++ b/tests/dibi/DateTime.phpt @@ -0,0 +1,21 @@ +setTimestamp(254400000)); +Assert::same(254400000, (new DateTime(254400000))->getTimestamp()); + +Assert::same('2050-08-13 11:40:00.000000', (string) new DateTime(2544000000)); +Assert::same('2050-08-13 11:40:00.000000', (string) (new DateTime)->setTimestamp(2544000000)); +Assert::same(is_int(2544000000) ? 2544000000 : '2544000000', (new DateTime(2544000000))->getTimestamp()); // 64 bit + +Assert::same('1978-05-05 00:00:00.000000', (string) new DateTime('1978-05-05'));