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