Skip to content

EspoCRM – Open Source CRM Application

date time value objects methods

Yuri Kuznetsov280e6e39879e
diff --git a/application/Espo/Core/Field/Date.php b/application/Espo/Core/Field/Date.php
index 1b46ba63d5..a245ce49b4 100644
--- a/application/Espo/Core/Field/Date.php
+++ b/application/Espo/Core/Field/Date.php
@@ -227,6 +227,24 @@ class Date implements DateTimeable
return $this->toDateTime() == $other->toDateTime();
}
+ /**
+ * Whether less than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isLessThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isLessThan($other) || $this->isEqualTo($other);
+ }
+
+ /**
+ * Whether greater than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isGreaterThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isGreaterThan($other) || $this->isEqualTo($other);
+ }
+
/**
* Create a today.
*/
diff --git a/application/Espo/Core/Field/DateTime.php b/application/Espo/Core/Field/DateTime.php
index 19026491e4..ebca7d2ba7 100644
--- a/application/Espo/Core/Field/DateTime.php
+++ b/application/Espo/Core/Field/DateTime.php
@@ -317,6 +317,24 @@ class DateTime implements DateTimeable
return $this->toDateTime() == $other->toDateTime();
}
+ /**
+ * Whether less than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isLessThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isLessThan($other) || $this->isEqualTo($other);
+ }
+
+ /**
+ * Whether greater than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isGreaterThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isGreaterThan($other) || $this->isEqualTo($other);
+ }
+
/**
* Create a current time.
*/
diff --git a/application/Espo/Core/Field/DateTimeOptional.php b/application/Espo/Core/Field/DateTimeOptional.php
index 4175610d44..35d94729af 100644
--- a/application/Espo/Core/Field/DateTimeOptional.php
+++ b/application/Espo/Core/Field/DateTimeOptional.php
@@ -394,6 +394,24 @@ class DateTimeOptional implements DateTimeable
return $this->toDateTime() == $other->toDateTime();
}
+ /**
+ * Whether less than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isLessThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isLessThan($other) || $this->isEqualTo($other);
+ }
+
+ /**
+ * Whether greater than or equals to a given value.
+ * @since 9.0.0
+ */
+ public function isGreaterThanOrEqualTo(DateTimeable $other): bool
+ {
+ return $this->isGreaterThan($other) || $this->isEqualTo($other);
+ }
+
/**
* Create a current time.
*/
diff --git a/tests/unit/Espo/Core/Field/Date/DateTest.php b/tests/unit/Espo/Core/Field/Date/DateTest.php
index 3121ffa438..5c08605ba1 100644
--- a/tests/unit/Espo/Core/Field/Date/DateTest.php
+++ b/tests/unit/Espo/Core/Field/Date/DateTest.php
@@ -187,6 +187,30 @@ class DateTest extends \PHPUnit\Framework\TestCase
$value->modify('+1 day')
)
);
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value->modify('-1 day')
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value->modify('+1 day')
+ )
+ );
}
public function testAddDays(): void
diff --git a/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php b/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
index ece3a5bc7d..c801929ec1 100644
--- a/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
+++ b/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
@@ -249,6 +249,30 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase
$value->modify('+1 minute')
)
);
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value->modify('-1 minute')
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value->modify('+1 minute')
+ )
+ );
}
public function testAddDays(): void
diff --git a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
index e9f14319c2..3f38ba0f8d 100644
--- a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
+++ b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
@@ -281,6 +281,30 @@ class DateTimeOptionalTest extends \PHPUnit\Framework\TestCase
$value->modify('+1 minute')
)
);
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value
+ )
+ );
+
+ $this->assertTrue(
+ $value->isGreaterThanOrEqualTo(
+ $value->modify('-1 minute')
+ )
+ );
+
+ $this->assertTrue(
+ $value->isLessThanOrEqualTo(
+ $value->modify('+1 minute')
+ )
+ );
}
public function testAddDays(): void