From f5dd6c6d37145ac14ce8eb6338773bed93a71ba1 Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Wed, 20 Sep 2023 18:16:17 +0200 Subject: [PATCH] Added Date::isNotBeforeOrEqualTo --- src/Date.php | 5 ++ tests/Date/IsNotBeforeOrEqualToTest.php | 66 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/Date/IsNotBeforeOrEqualToTest.php diff --git a/src/Date.php b/src/Date.php index 87adc3a..bef2799 100644 --- a/src/Date.php +++ b/src/Date.php @@ -81,6 +81,11 @@ public function isBeforeOrEqualTo(self $date): bool return $this->toDateTimeImmutable() <= $date->toDateTimeImmutable(); } + public function isNotBeforeOrEqualTo(self $date): bool + { + return !($this->toDateTimeImmutable() <= $date->toDateTimeImmutable()); + } + public function isAfter(self $date): bool { return $this->toDateTimeImmutable() > $date->toDateTimeImmutable(); diff --git a/tests/Date/IsNotBeforeOrEqualToTest.php b/tests/Date/IsNotBeforeOrEqualToTest.php new file mode 100644 index 0000000..d612c06 --- /dev/null +++ b/tests/Date/IsNotBeforeOrEqualToTest.php @@ -0,0 +1,66 @@ +isNotBeforeOrEqualTo($comparator)); + } + + /** + * @return array + */ + public function dataProvider(): array + { + return [ + 'previous year' => [ + true, + Date::fromString('2022-10-08'), + Date::fromString('2021-10-08'), + ], + 'same date' => [ + false, + Date::fromString('2022-10-08'), + Date::fromString('2022-10-08'), + ], + 'next year' => [ + false, + Date::fromString('2022-10-08'), + Date::fromString('2023-10-08'), + ], + 'next month' => [ + false, + Date::fromString('2022-10-08'), + Date::fromString('2022-11-08'), + ], + 'next day' => [ + false, + Date::fromString('2022-10-08'), + Date::fromString('2022-10-09'), + ], + ]; + } +}