diff --git a/.gitattributes b/.gitattributes index 3de7c36c..1f9b9240 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,5 +4,5 @@ /CONTRIBUTING.md export-ignore /phpcs.xml.dist export-ignore /phpstan.neon export-ignore -/benchmark export-ignore +/performance export-ignore /generator export-ignore diff --git a/generator/tests/DateTimeImmutableTest.php b/generator/tests/DateTimeImmutableTest.php index b4a99747..4ae5ad38 100644 --- a/generator/tests/DateTimeImmutableTest.php +++ b/generator/tests/DateTimeImmutableTest.php @@ -142,4 +142,15 @@ public function testSerialize() $this->assertEquals($safeDatetime->getTimestamp(), $newDatetime->getTimestamp()); $this->assertEquals($safeDatetime->getTimezone(), $newDatetime->getTimezone()); } + + public function testComparaison(): void + { + $safeDateTime = new \Safe\DateTimeImmutable(); + $phpDateTime = new \DateTimeImmutable(); + $timeLimit = \DateInterval::createFromDateString('2 hours'); + + $a = $safeDateTime->modify('+3 hours') < $safeDateTime->add($timeLimit); + $b = $phpDateTime->modify('+3 hours') < $phpDateTime->add($timeLimit); + $this->assertEquals($b, $a); + } } \ No newline at end of file diff --git a/lib/DateTimeImmutable.php b/lib/DateTimeImmutable.php index 51cf041e..a0956492 100644 --- a/lib/DateTimeImmutable.php +++ b/lib/DateTimeImmutable.php @@ -28,14 +28,14 @@ class DateTimeImmutable extends \DateTimeImmutable */ public function __construct($time = 'now', $timezone = null) { - parent::__construct(); + parent::__construct($time, $timezone); $this->innerDateTime = new parent($time, $timezone); } //switch from regular datetime to safe version private static function createFromRegular(\DateTimeImmutable $datetime): self { - $safeDatetime = new self(); + $safeDatetime = new self($datetime->format('Y-m-d H:i:s'), $datetime->getTimezone()); //we need to also update the wrapper to not break the operators '<' and '>' $safeDatetime->innerDateTime = $datetime; return $safeDatetime; }