From 8032dd87e3ea772628d903047af057dd764def39 Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Wed, 20 Sep 2023 14:07:10 +0200 Subject: [PATCH] Added DateTime::isNotBeforeOrEqualTo --- src/DateTime.php | 5 ++ tests/DateTime/IsNotBeforeOrEqualToTest.php | 86 +++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/DateTime/IsNotBeforeOrEqualToTest.php diff --git a/src/DateTime.php b/src/DateTime.php index 1a18a17..0cdcfc9 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -132,6 +132,11 @@ public function isBeforeOrEqualTo(self $dateTime): bool return $this->dateTime <= $dateTime->dateTime; } + public function isNotBeforeOrEqualTo(self $dateTime): bool + { + return $this->dateTime >= $dateTime->dateTime; + } + public function isBefore(self $dateTime): bool { return $this->dateTime < $dateTime->dateTime; diff --git a/tests/DateTime/IsNotBeforeOrEqualToTest.php b/tests/DateTime/IsNotBeforeOrEqualToTest.php new file mode 100644 index 0000000..45dd738 --- /dev/null +++ b/tests/DateTime/IsNotBeforeOrEqualToTest.php @@ -0,0 +1,86 @@ +isNotBeforeOrEqualTo($comparator)); + } + + /** + * @return array + */ + public function dataProvider(): array + { + return [ + 'previous year' => [ + false, + DateTime::fromString('2021-10-08 15:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'is equal' => [ + true, + DateTime::fromString('2022-10-08 15:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next year' => [ + true, + DateTime::fromString('2023-10-08 15:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next month' => [ + true, + DateTime::fromString('2022-11-08 15:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next day' => [ + true, + DateTime::fromString('2022-10-09 15:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next hour' => [ + true, + DateTime::fromString('2022-10-08 16:00:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next minute' => [ + true, + DateTime::fromString('2022-10-08 15:01:00'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next second' => [ + true, + DateTime::fromString('2022-10-08 15:00:01'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + 'next millisecond' => [ + true, + DateTime::fromString('2022-10-08 15:00:00.000001'), + DateTime::fromString('2022-10-08 15:00:00'), + ], + ]; + } +}